Getting Javascript TypeError when trying to access method on my model
I created a simple model and am trying to test out the setter method on it. When using it in the Chrome javascript console I get a TypeError with a type of "undefined_method".
Here's a link to the code http://jsfiddle.net/cpeele00/Rq4Tj/
I am call开发者_JAVA百科ing it like so:
Model.Movie.setTitle('Resident Evil');
Any help would be greatly appreciated.
You're calling change
on the string 'Resident Evil'
:
setTitle : function(title){
this.title = title;
this.title.change(function(){ // <-- here
console.log('title has changed to: ' + title);
});
},
There is no such method defined on strings. If you're trying to fire a change
event to notify listeners that the title
changed, you'll have to approach this from a different angle.
There is a problem with setTitle() method, if I comment out the three lines commented below it works.
setTitle : function(title){
this.title = title;
console.log(title);
//this.title.change(function(){
// console.log('title has changed to: ' + title);
//});
},
精彩评论