Javascript. The "this" keyword


Need help!
I don't understand why this message appears:

TypeError: bob.setAge is not a function

// 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


So for some reason you have added parenthesis to bob.setAge = setAge();

All you have to do is take out the parenthesis (). And your good as gold :slight_smile:

If that solved it please mark my answer as the solution, thanks.


actually, it has already been there)
i solved it a few minutes earlier. but still i can't get some stuff of this

thanks, anyway!)


Ah okay, no worries :slight_smile:




This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.