Hi,
I've got this very simple code that I don't understand (output follows
code).
Why does access to the _field variable fail without the "this"? I
thought that once _field was added to the prototype object (an
Integer, in this case), it was just like any other property of the
object (like _val, which is set in the Integer ctor).
================================
Integer = function(i)
{
this._val = i;
}
Foo = function()
{
writeln("This Foo value = " + this._val + "!")
writeln("Foo value = " + _val + "!")
writeln("This Foo field = " + this._field + "!");
writeln("Foo field = " + _field + "!");
}
Foo.prototype = new Integer(1);
Foo.prototype._field = "foo field";
====================================
js>run("test2.js");
This Foo value = 1!
Foo value = 1!
This Foo field = foo field!
test2.js:11 ReferenceError: _field is not defined