javascript继承--对象冒充

function Parent(name){
this.name=name;
this.sayHello=function(){
alert(this.name);
}
}
function child(name,hobby){
this.method=Parent;
/*
调用Parent()函数,添加了name,sayHello属性
*/
this.method(name);

delete this.method;
}
var ch=new child("小张","打酱油");
ch.sayHello();
posted @ 2012-04-08 18:18  unbreakable  阅读(157)  评论(0编辑  收藏  举报