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

首頁 > 編程 > JavaScript > 正文

JavaScript中繼承用法實例分析

2019-11-20 12:27:57
字體:
來源:轉載
供稿:網友

本文實例分析了JavaScript中繼承的用法。分享給大家供大家參考。具體如下:

// define the Person Classfunction Person() {}Person.prototype.walk = function(){ alert ('I am walking!');};Person.prototype.sayHello = function(){ alert ('hello');};// define the Student classfunction Student() { // Call the parent constructor Person.call(this);}// inherit PersonStudent.prototype = new Person();// correct the constructor pointer because it points to PersonStudent.prototype.constructor = Student;// replace the sayHello methodStudent.prototype.sayHello = function(){ alert('hi, I am a student');}// add sayGoodBye methodStudent.prototype.sayGoodBye = function(){ alert('goodBye');}var student = new Student();student.sayHello();student.walk();student.sayGoodBye();// check inheritancealert(student instanceof Person); // true alert(student instanceof Student); // true

希望本文所述對大家的javascript程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阿鲁科尔沁旗| 喜德县| 合肥市| 连山| 云南省| 拉孜县| 娱乐| 金阳县| 柏乡县| 临武县| 乐昌市| 南川市| 盐城市| 阿图什市| 利津县| 新沂市| 丹巴县| 象山县| 连城县| 门头沟区| 萨迦县| 弋阳县| 尼玛县| 岳普湖县| 华安县| 周口市| 宜章县| 贵港市| 博客| 印江| 子洲县| 邵阳县| 庆元县| 米脂县| 奎屯市| 武平县| 黔西| 共和县| 深泽县| 常宁市| 水城县|