开发者

Getting Javascript TypeError when trying to access method on my model

开发者 https://www.devze.com 2023-04-13 00:06 出处:网络
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\".

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);
        //});

    },
0

精彩评论

暂无评论...
验证码 换一张
取 消