function Parent(hello)
{
this.hello = hello;
}
Parent.prototype.sayHello = function () {
alert(this.hello);
};
function Child(hello,word)
{
Parent.call(this,hello);
this.word = word;
}
Child.prototype = new Parent();
Child.prototype.sayWord = function ()
{
alert(this.word);
};
var child = new Child("hhh","233");
child.sayHello();
{
this.hello = hello;
}
Parent.prototype.sayHello = function () {
alert(this.hello);
};
function Child(hello,word)
{
Parent.call(this,hello);
this.word = word;
}
Child.prototype = new Parent();
Child.prototype.sayWord = function ()
{
alert(this.word);
};
var child = new Child("hhh","233");
child.sayHello();
child.sayWord();
注:推荐使用这个方式(父子对象属性和方法互补干扰)
本文通过实例解析JavaScript中子类继承父类的方法,展示如何在实际项目中运用面向对象编程思想。
2745

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



