function Parent(username)
{
this.username = username;
this.sayHello = function()
{
alert(this.username);
}
}
function Child(username,pwd)
{
Parent.call(this,username);
this.pwd = pwd;
this.sayPwd = function(){
alert(this.pwd);
}
}
var p = new Parent("admin123");
var c = new Child("admin1","admin12");
p.sayHello ();
c.sayHello ();
c.sayPwd ();
本文深入探讨了JavaScript中函数作为构造器的高级用法,并通过实例展示了如何利用构造器创建对象,实现对象属性和方法的封装。同时,文章还演示了如何在子类中继承父类的属性和方法,以及如何在子类中覆盖或扩展这些属性和方法。
1298

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



