17. "This" works for everyone. - Slightly confused


The line:

bob.setAge = setAge;

...is causing me a little consternation since the name of what I believe to be a property is the same as the method too. Would the following nomenclature work? Thanks for helping to clarify this issue.

var method_setAge = function (newAge) {
  this.age = newAge;

var bob = new Object();
bob.age = 30;
bob.property_setAge = method_setAge;



I dont see this line

In your code...


Functions are values like any others, you're doing the same thing with

var method_setAge = function (newAge) {

You create a function, and let method_setAge refer to it.



Thank you for the reply.

Two things:

  1. This is a small point perhaps, but am I using that correct terminology? For example in the statement: bob.property_setAge = method_setAge; is the left hand of the statement called a property? And, is the right hand part of the statement called a method?

  2. Perhaps what is confusing me is that we're assigning an argument to what I'm calling a property later in the script: bob.property_setAge(35); I've become used to seeing an argument being passed to a function in our lessons.

Thanks again to our community for some help on this.


A function is a value.

If you assign a value to a property, you can use it again later when looking it up.


I've the same question. I don't get why I need to set a property under bob and call it a method instead of calling the method itself with the new value of 35.

I just don't get why I need:

And why can't I call bob.method_setAge(35); instead.