J
javadesigner
Hi:
Consider this:
-----------------------------
function bar() { } ;
bar.prototype.y = 'hello';
function foo() { };
var f = new foo(); //Y
foo.prototype = bar.prototype; //X
alert (f.y);
------------------------------
This results in alerting undefined
Now consider this:
------------------------------------
function bar() { } ;
bar.prototype.y = 'hello';
function foo() { };
foo.prototype = bar.prototype; //X
var f = new foo(); //Y
alert (f.y);
----------------------------------
This alerts 'hello'
The only difference between the two examples is that line marked X and
Y have been switched. But prototypes are dynamic, so why does the
first example NOT alert 'hello' ???
Best regards,
--j
Consider this:
-----------------------------
function bar() { } ;
bar.prototype.y = 'hello';
function foo() { };
var f = new foo(); //Y
foo.prototype = bar.prototype; //X
alert (f.y);
------------------------------
This results in alerting undefined
Now consider this:
------------------------------------
function bar() { } ;
bar.prototype.y = 'hello';
function foo() { };
foo.prototype = bar.prototype; //X
var f = new foo(); //Y
alert (f.y);
----------------------------------
This alerts 'hello'
The only difference between the two examples is that line marked X and
Y have been switched. But prototypes are dynamic, so why does the
first example NOT alert 'hello' ???
Best regards,
--j