手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >使用apply方法实现javascript中的对象继承
使用apply方法实现javascript中的对象继承
摘要:复制代码代码如下://使用apply方法实现对象继承functionParent(username){this.username=usern...

复制代码 代码如下:

<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>

【使用apply方法实现javascript中的对象继承】相关文章:

javascript中clipboardData对象用法

谈一谈javascript中继承的多种方式

Jquery使用val方法读写value值

解析javascript中鼠标滚轮事件

javascript使用Promise对象实现异步编程

详解Javascript中的Object对象

JavaScript正则表达式的分组匹配详解

用JavaScript实现对话框的教程

javascript的 {} 语句块详解

深入理解JavaScript中的对象

精品推荐
分类导航