Does Backbone.js have a hard dependency on jQuery?

后端 未结 4 1455
名媛妹妹
名媛妹妹 2021-02-07 02:17

According to backbone js website:

Backbone\'s only hard dependency is Underscore.js ( > 1.3.1). For RESTful persistence, history support via Backbone.Rout

相关标签:
4条回答
  • 2021-02-07 02:42

    While Backbone.View does depend on a DOM manipulation library, ie you can't use vanilla javascript that is not organized in to a library of some sort, you can configure Backbone to use whatever library you'd like.

    See the following from the Backbone source:

    // Set the JavaScript library that will be used for DOM manipulation and
    // Ajax calls (a.k.a. the `$` variable). By default Backbone will use: jQuery,
    // Zepto, or Ender; but the `setDomLibrary()` method lets you inject an
    // alternate JavaScript library (or a mock library for testing your views
    // outside of a browser).
    Backbone.setDomLibrary = function(lib) {
      $ = lib;
    };
    

    Calling this method will allow you to use whatever library you want.

    For example:

    Backbone.setDomLibrary(myCustomLibrary);
    
    0 讨论(0)
  • 2021-02-07 02:49

    Backbone is now even easier to decouple from jQuery.
    Check this out:

    Using Backbone without jQuery

    0 讨论(0)
  • 2021-02-07 02:55

    You can use the Backbone.Model without jQuery, but Backbone.View will require either jQuery or Zepto, just like the docs state.

    0 讨论(0)
  • 2021-02-07 02:58

    Try to use jBone, this is library for DOM manipulations in modern browsers, jBone developed special for Backbone, only 2kb gzipped and jQuery like API.

    0 讨论(0)
提交回复
热议问题