Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backbone.js - "Object [object Object] has no method 'listenTo'"

Question: I have code that works like this: BottomPaneView

initialize: function() {
  ...
  this.childView = null
  ...
  this.listenTo(this.childView, "findUnit", this.findUnit);
}

in another function,

{
  ...
  this.childView = new TrackingView(...);
  this.childView.render()
  ...
}

The last line in initialize throws "Uncaught TypeError: Object [object Object] has no method 'listenTo' ". Doesn't this refer to a View object?

Thanks!

like image 445
brokethebuildagain Avatar asked Mar 16 '26 17:03

brokethebuildagain


2 Answers

Ok, so the problem was I was using v0.9.0, and backbone didn't implement listenTo until 0.9.9. I updated to v1.0.0 and everything worked.

Note that before this, I moved the problem line below the this.childView.render() in the second function to make sure the argument was initialized. I don't know if what I was doing initially would have worked.

like image 174
brokethebuildagain Avatar answered Mar 20 '26 00:03

brokethebuildagain


The this.childView must be an instance of Backbone.View. Do a console.log before the binding statement to check this.

like image 39
Venkat Kotra Avatar answered Mar 19 '26 23:03

Venkat Kotra