使用apply方法实现javascript中的对象继承

时间:2013-12-16    点击:96   
复制代码 代码如下:

<script type="text/javascript">
//使用apply方法实现对象继承

function Parent(username) {
this.username = username;
this.sayHello = function() {
alert(this.username);
}
}

function Child(username, password) {
Parent.apply(this, new Array(username));
//和下面一样
//Parent.apply(this, [username]);

this.password = password;

this.sayWorld = function() {
alert(this.password);
}
}
var parent = new Parent("zhangsan");
var child = new Child("lisi", "123");

parent.sayHello();
child.sayHello();
child.sayWorld();

</script>
js采用map取到id集合组并且实现点击一行选中一行
js捕获鼠标滚轮事件代码
使用firebug进行调试javascript的示例
javascript和jquery修改a标签的href属性
JavaScript修改css样式style动态改变元素样式
> 返回     
地址:上海市普陀区胶州路941号长久商务中心 电话: QQ:
© Copyright 2012 上海网络 Product All Rights Reserved