The "this" Keyword,whats the problem?


#1

this is my code,i dont understand where is the problem
var bob = new Object();
bob.age = 30;

var bob.setAge = function (newAge) {
this.age = newAge;

};

bob.setAge(50);


#2

I go it...
// here we define our method using "this", before we even introduce bob
var setAge = function (newAge) {
this.age = newAge;
};
// now we make bob
var bob = new Object();
bob.age = 30;
// and down here we just use the method we already made
bob.setAge = setAge;

// change bob's age to 50 here
bob.setAge(50);