In your call to takeTwoNums
, this
refers to the same object that myObj
refers to. That object doesn't have an x
property. It has a takeTwoNums
property, and a couple of properties it inherits from Object.prototype
like toString
and such, but no x.
The x
is an argument to the method. You just reference it as x
. Calling the method doesn't make this
refer to an object that has the arguments as properties.
You may be confusing this with something like this:
function Thingy(x) {
this.x = x;
}
// Then
var t = new Thingy(42);
In that case, because we used new
, it created a new object and then called Thingy
with this
referring to that new object and we created a property on it called x
that we initialized with the value of the argument x
. But that's another thing entirely than just calling a function.