<script>
/*
* js实现继承的练习
prototype原型继承
*/
function Parent(){
}
Parent.test=new function(){
alert("我是父类方法");
}
function Child(){
}
Child.prototype=new Parent();
var c=new Child();
alert(c.test());
</script>
/*
* js实现继承的练习
prototype原型继承
*/
function Parent(){
}
Parent.test=new function(){
alert("我是父类方法");
}
function Child(){
}
Child.prototype=new Parent();
var c=new Child();
alert(c.test());
</script>
本文介绍了一种使用JavaScript实现继承的方法,通过将父类实例赋值给子类的prototype属性来达到继承的目的。示例中定义了Parent和Child两个类,并展示了如何让Child继承Parent的方法。
238

被折叠的 条评论
为什么被折叠?



