7
votes

I has a view with this event:

var View = Backbone.View.extend({
  el: $('#test'),
  events: {
    "change input": "test"
  },
  test: function(e) {
    console.log("test");
  }
});

var view = new View();

With backbone 0.9.9 it work, but with backbone 0.9.10 I got this error: Uncaught TypeError: Object [object Object] has no method 'off'. What I need to change to work with events on backbone 0.9.10?

I'm using this cdn's

http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.10/backbone-min.js

Thanks

2
Is this error being triggered when .test() was invoked? It doesn't seem like test is doing anything in regards to .off(). Is there some other code that is calling .off()?DashK
.test() is only invoked when using backbone 0.9.9. The error appear when the page load, before I do any interaction with the page.Camilo
If the error appears before any interaction with the page, the source of the problem is elsewhere. Are you able to provide the code that throws the error? (If you look at Firebug, you should be able to get a line number that throws the exception.)DashK
I deleted all the code on my application and leave only the part with the problem. I got the same results, work with 0.9.9, doesn't work with 0.9.10. This is the error I got on chrome: Uncaught TypeError: Object [object Object] has no method 'off' backbone-min.js:38Camilo
Is it possible to put the code in JSFiddle/JSBin?DashK

2 Answers

12
votes

I was using jquery 1.5.2 and the method off was introduced on jquery 1.7.0. Backbone 0.9.9 require that el contain the method unbind while Backbone 0.9.10 require that el contain the method off. The method unbind exist on jquery 1.5.2 and that was the reason why my code worked with backbone 0.9.9.

1
votes

Try this...

var Test = Backbone.View.extend({
  events: {
    "change input": "test"
  },

  initialize: function() {
    this.setElement($('#test'));
  },

  test: function(e) {
    alert("test");
  }
});

var test = new Test();

Or, this would be even better...

var Test = Backbone.View.extend({
  events: {
    "change input": "test"
  },

  test: function(e) {
    alert("test");
  }
});

var test = new Test({
  el: $('#test')
});