S
satyajit
I am trying to learn the concept of constructors in ECMAScript. I
executed following code (See execution in Rhino JavaScript shell):
function Foo(a)
{
this.a = a;
}
function Bar(b)
{
this.b = b;
}
Bar.prototype = new Foo(1);
var x = new Foo(2);
var y = new Bar(3);
Now I expect y.constructor to give me Bar, but I am getting Foo.
Can anybody explain?
Following the execution sequence in Rhino JavaScript shell:
Rhino 1.6 release 5 2006 11 18
js> function Foo(a)
{
this.a = a;
}
js> function Bar(b)
{
this.b = b;
}
js> Bar.prototype = new Foo(1);
[object Object]
js> var x = new Foo(2);
js> var y = new Bar(3);
js> x.constructor
function Foo(a) {
this.a = a;
}
js> y.constructor
function Foo(a) {
this.a = a;
}
Regards,
Satyajit
executed following code (See execution in Rhino JavaScript shell):
function Foo(a)
{
this.a = a;
}
function Bar(b)
{
this.b = b;
}
Bar.prototype = new Foo(1);
var x = new Foo(2);
var y = new Bar(3);
Now I expect y.constructor to give me Bar, but I am getting Foo.
Can anybody explain?
Following the execution sequence in Rhino JavaScript shell:
Rhino 1.6 release 5 2006 11 18
js> function Foo(a)
{
this.a = a;
}
js> function Bar(b)
{
this.b = b;
}
js> Bar.prototype = new Foo(1);
[object Object]
js> var x = new Foo(2);
js> var y = new Bar(3);
js> x.constructor
function Foo(a) {
this.a = a;
}
js> y.constructor
function Foo(a) {
this.a = a;
}
Regards,
Satyajit