国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

使用apply方法實現javascript中的對象繼承

2024-05-06 15:57:35
字體:
來源:轉載
供稿:網友
javascript中的對象繼承的方法有很多,在接下來的文章中為大家介紹下使用apply方法是如何實現的

復制代碼 代碼如下:


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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 广饶县| 彩票| 曲周县| 拜城县| 临安市| 阿尔山市| 丰顺县| 新化县| 茌平县| 连城县| 资中县| 汝南县| 石渠县| 哈密市| 利辛县| 西吉县| 克东县| 镇远县| 左云县| 镇赉县| 鲁山县| 大余县| 新郑市| 金华市| 绥棱县| 金乡县| 德清县| 沽源县| 勐海县| 阿城市| 宾川县| 阿荣旗| 三穗县| 安泽县| 方城县| 九台市| 南昌市| 潞城市| 望谟县| 西畴县| 玛曲县|