javascript使用call方式实现对象继承

来源:互联网 发布:win7网络打印机离线 编辑:程序博客网 时间:2024/05/17 01:00

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 ();




0 0