function Foo() {
};
function Foo2() {
};
function Bar() {
};
Bar.prototype = new Foo();
var v = new Bar();
alert(v.constructor);
Bar.prototype = new Foo2();
alert(v.constructor);
为什么第二个alert也是function Foo() {
};
};
function Foo2() {
};
function Bar() {
};
Bar.prototype = new Foo();
var v = new Bar();
alert(v.constructor);
Bar.prototype = new Foo2();
alert(v.constructor);
为什么第二个alert也是function Foo() {
};
你原來的V在改變之前就建立了,當然不會變。function Foo() {
};
function Foo2() {
};
function Bar() {
};
Bar.prototype = new Foo();
var v = new Bar();
alert(v.constructor);
Bar.prototype = new Foo2();
var v2 = new Bar();
alert(v2.constructor);
<script>
function Foo() {
};
function Foo2() {
};
function Bar() {
};
Bar.prototype = new Foo();
Bar.prototype = new Foo2();
var v = new Bar();
alert(v.constructor);</script>这个试验就很明显了,new Bar()是克隆了一份,而不是指向Bar.prototype的指针