Julian Turner wrote:
Thomas 'PointedEars' Lahn wrote:
[snip]
It was probably not a good idea to remove context here.
[...]
Unless I have misunderstood something (quite likely) at this point the
prototype functions are already in place in memory.
Probably we have a mutual misunderstanding. Say, for example, that the
constructor is the following method:
function MyObject(x)
{
this.foo = function(y)
{
return x;
}
}
then objects created through
var newObject = new MyObject(...);
have a `foo' method that is unique to an MyObject object, regarding that
there is not the same method for other MyObject objects unless the
conditions for creation (here: the value passed to the constructor) are
the same. If that method is modified, other MyObject objects and objects
derived from MyObject are not affected.
If the constructor and prototype are instead defined as
function MyObject(x)
{
}
MyObject.prototype.foo = function(y)
{
return x;
}
then MyObject objects would also have `foo' method, however a) its return
value depends solely on the value of `x' when it is _called_ and b) all
MyObject objects would share this method since it is accessed through the
prototype chain. Modifying that method would mean that it is modified for
all MyObject objects as well as for all objects derived from MyObject,
unless overwritten there.
That prototype method is not created when the constructor is called (with
`new') but right after the latter was instantiated (provided there is no
code between that forces instantiation).
Did you mean that in the first place?
PointedEars