0

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 calling it like so:

Model.Movie.setTitle('Resident Evil');

Any help would be greatly appreciated.

2 Answers 2

0

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks Matt, I appreciate it. Can you point me in the right direction for how to accomplish this please? :-)
thanks Matt. Based on some of those links, here's what I have which is still throwing the same error setTitle : function(title){ this.title = title; //console.log(this.title); this.title.bind('titleChangedEvent', function(){ console.log('your title changed') }); this.title.trigger('titleChangedEvent'); },
Dude, title is still a string. It doesn't have bind or trigger functions. It's just a string.
Dude, this is exactly why I am asking for assistance. Instead of sarcastically stating how easy searching is (by the way none of those helped) just provide a simple code example. If you are not able, then please don't waste my time with your comments.
|
0

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

    },

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.