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();
{
}
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();
缺点是:无法给构造函数传递参数