Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Dependencies của Backbone.js trong JavaScript

Hard dependency (bắt buộc): Underscore.js — thư viện functional programming helpers (map, filter, reduce, template...). Backbone không chạy nếu thiếu.

Soft dependencies (tùy feature)

  • jQuery / Zepto: DOM manipulation cho Backbone.View (event delegation, $el).
  • json2.js: JSON parse/stringify cho IE cũ (hiện đại không cần).
  • RESTful persistence: Backbone.sync mặc định dùng jQuery.ajax — có thể override.
  • History/Routing: Backbone.Router + Backbone.History (cần pushState support hoặc hash fallback).

Kiến trúc Backbone

  • Model: Data + business logic + validation.
  • Collection: Tập hợp Model, hỗ trợ sort/filter/event.
  • View: Render UI, bind event, listen model change.
  • Router: Client-side routing (hash/history).
  • Events: Mixin event system (on/off/trigger).

Backbone nhẹ (~7KB gzipped), unopinionated, phù hợp app trung bình.