欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用apply方法實(shí)現(xiàn)javascript中的對(duì)象繼承

 更新時(shí)間:2013年12月16日 17:18:14   作者:  
javascript中的對(duì)象繼承的方法有很多,在接下來(lái)的文章中為大家介紹下使用apply方法是如何實(shí)現(xiàn)的
復(fù)制代碼 代碼如下:

<script type="text/javascript">
//使用apply方法實(shí)現(xiàn)對(duì)象繼承

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>

相關(guān)文章

最新評(píng)論