Search code examples
pluginsjquery-pluginsbackbone.js

How to use backbone js with some legacy plugins?


I've working on a project and I'm using some jquery plugins, right now I'm trying to update my code to use backboje js but it's not clear how to put together those old plugins with backbone js.

the most important plugin I want to use is jcvl (http://code.google.com/p/jcvl/) but I'm trying to put this question general to get more ideas about how to integrate any pluggin with backbone.


Solution

  • Backbone only creates one global variable, Backbone, so there shouldn't be any conflicts with any jQuery plugins. Backbone also depends on Underscore.js, which also only creates one global variable, _, so it also shouldn't cause any conflicts. And if there is a conflict, both Backbone and Underscore.js offer you a noConflict() option.

    I've been using Backbone with jQuery plugins for a while and haven't encountered any problems. You would use the plugin in the same way as before you introduced Backbone. For example:

    var MyView = Backbone.View.extend({
    
      render: function(){
        $(this.el).html('<div class="foo"></div>');
        this.$('.foo').somejQueryPlugin();
      }
    });