function SuperType(){
this.name='s;'
this.colors = ["red", "blue", "green"];
}
function SubType(){
}
//inherit from SuperType
SubType.prototype = new SuperType();
var instance1 = new SubType();
var instance2 = new SubType();
instance1.name='ssss';
instance1.colors=["red", "blue"];
alert(instance1.colors); //"red,blue,green,black"
alert(instance1.name); //"ssss"
alert(instance2.colors); //"red,blue,green,black"
alert(instance2.name); //"s"
instance2.name 为什么没有改变
function SuperType(){
this.name='sdsd';
this.colors = ["red", "blue", "green"];
}
function SubType(){
//inherit from SuperType
SuperType.call(this);
}
var instance1 = new SubType();
instance1.colors.name='aaaaaaa';
instance1.colors.push("black");
alert(instance1.colors); //"red,blue,green,black"
alert(instance1.name); //"a"
var instance2 = new SubType();
instance2.colors.name='bbbbbbb';
alert(instance2.colors); //"red,blue,green"
alert(instance2.name); //"a"
instance2.name和instance1.name 都没有改变
慕容3067478
相关分类