var sound = {echo: function() { alert("sound"); } };function Person() {this.name="name_";};Person.prototype = sound;//----早点绑上去----var fo1o = new Person(); var xxxxxx=Person.prototype;//----迟了绑上去----??xxxxxx.yyyy="yyyy_"; alert(fo1o.echo);//alert(undefined); alert(fo1o.yyyy);//alert(undefined); //////////////////////////////////////////////////////////////////////////////////////////////////// var sound = {echo: function() { alert("sound"); } };function Person() {this.name="name_";};var fo1o = new Person(); Person.prototype = sound;//----迟了绑上去----var xxxxxx=Person.prototype;//----迟了绑上去----??xxxxxx.yyyy="yyyy_"; alert(fo1o.echo);//alert(function(){....}); alert(fo1o.yyyy);//alert("yyyy_");//为什么alert(fo1o.yyyy)会受到影响。
而且,你两个例子,写反了。alert的显示值,写反了
function Person() {}; Person.prototype = {a:1}; var fo1o = new Person(); Person.prototype = {a:2}; var fo2o = new Person(); alert(fo1o.a);//1 alert(fo2o.a);//2对象继承的不是构造函数本身,而是构造函数的prototype 当构造函数的prototype被重新赋值后,构造函数所创建的新对象也会不同
var sound = {echo: function() { alert("sound"); } }; function Person() {this.name="name_";};
var test_1 = new Person();//test_1先实例 Person.prototype.sound; var test_2 = new Person();//test_2后实例var xxxxxx=Person.prototype;//----迟了绑上去---- xxxxxx.yyyy="yyyy_1";
alert(fo1o.yyyy);//alert(undefined);
////////////////////////////////////////////////////////////////////////////////////////////////////
var sound = {echo: function() { alert("sound"); } };function Person() {this.name="name_";};var fo1o = new Person(); Person.prototype = sound;//----迟了绑上去----var xxxxxx=Person.prototype;//----迟了绑上去----??xxxxxx.yyyy="yyyy_"; alert(fo1o.echo);//alert(function(){....});
alert(fo1o.yyyy);//alert("yyyy_");//为什么alert(fo1o.yyyy)会受到影响。
Person.prototype = {a:1};
var fo1o = new Person();
Person.prototype = {a:2};
var fo2o = new Person(); alert(fo1o.a);//1
alert(fo2o.a);//2对象继承的不是构造函数本身,而是构造函数的prototype
当构造函数的prototype被重新赋值后,构造函数所创建的新对象也会不同
http://write.blog.csdn.net/postlist
http://blog.csdn.net/xanxus46/article/details/23873475
var sound = {echo: function() { alert("sound"); } };
function Person() {this.name="name_";};
var test_1 = new Person();//test_1先实例
Person.prototype.sound;
var test_2 = new Person();//test_2后实例var xxxxxx=Person.prototype;//----迟了绑上去----
xxxxxx.yyyy="yyyy_1";
alert(test_1.echo);//undefined
alert(test_1.yyyy);//alert("yyyy_");
alert(test_2.echo);//undefined
alert(test_2.yyyy);//alert("yyyy_");
//结果什么事 yyyy存在,而echo不存在。
//我都打错字吗?
OK