国产探花免费观看_亚洲丰满少妇自慰呻吟_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程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 高青县| 东乌珠穆沁旗| 海原县| 贵南县| 邻水| 翁牛特旗| 邓州市| 抚松县| 竹溪县| 连州市| 湄潭县| 临猗县| 新乐市| 康马县| 惠州市| 安远县| 磐石市| 茂名市| 连江县| 聂拉木县| 沂南县| 雅江县| 元氏县| 巴彦县| 上栗县| 施秉县| 榆林市| 东城区| 湘西| 罗城| 沙洋县| 黄山市| 宁武县| 临沭县| 青铜峡市| 舒兰市| 民和| 本溪| 北京市| 锦屏县| 天等县|