javscript通过原型链方式显示对象继承

来源:互联网 发布:腾讯软件助手 编辑:程序博客网 时间:2024/06/05 11:04
function Parent()
{

}


Parent.prototype.hello = "hello";
Parent.prototype.sayHello = function()
{
alert(this.hello);
};


function Child()
{

}
Child.prototype = new Parent();
//扩展属性
Child.prototype.word ="word";
Child.prototype.sayWord = function()
{
alert(this.word);
};


var child = new Child();
child.sayHello();

child.sayWord();


缺点是:无法给构造函数传递参数

0 0
原创粉丝点击