//一个对象
var stooge ={
"first_name":"xiao",
"last_name": "long",
sayhello:function(){
alert("hello,my name is:"+this.first_name+this.last_name);
}
};
//为stooge添加一个新的属性job
stooge.job ="doctor";
//这样是对象引用,
var x = stooge;
var warlock = function(){
}
//warlock函数以stooge对象为原型,新建一个warlock对象的时候,就会继承stooge的属性
warlock.prototype = stooge;
var warlockchild = new warlock();
alert(warlockchild.first_name);
warlockchild.sayhello();
var nevermore = stooge;
warlockchild.attack(nevermore);
alert("防御力无:"+warlockchild.defensepower);
//给原型stooge添加defensepower属性,以它为原型的warlock便立刻又了defensepower属性
stooge.defensepower = 300;
alert("添加了防御力属性:"+warlockchild.defensepower);
//nevermore和jugg引用的是同一个对象stooge,它们是同一个人
//var jugg = stooge;
//warlockchild.attack(jugg);
//遍历一个warlock函数的实例对象,如果遍历warlock函数本身就不行
var attr;
for(attr in warlockchild){
if(typeof warlockchild[attr]!=='function'){
alert(attr+":"+warlockchild[attr]);
}else{
//eval("warlockchild."+attr+"();");
//warlockchild[attr];
}
}