Taken from ejohn.org:
function katana(){
this.isSharp = true;
}
katana();
assert( isSharp === true, "A global object now exists with that name and value." );
This comes out as true.
Could anyone explain this?
Inside the function we see this.isSharp = true
, doesn't that create an object
which should have the propery isSharp
, and its value would be true
? (I would think the object is katana, since it calls the function, so katana.isSharp
would be true
).
In other words, what exactly does the this
refer to?
How come isSharp
is created as an object?