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

首頁 > 語言 > JavaScript > 正文

JavaScript中繼承用法實例分析

2024-05-06 16:20:26
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了JavaScript中繼承用法,以實例形式較為詳細的分析了javascript實現繼承的相關技巧,需要的朋友可以參考下

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

 

 
  1. // define the Person Class 
  2. function Person() {} 
  3. Person.prototype.walk = function(){ 
  4. alert ('I am walking!'); 
  5. }; 
  6. Person.prototype.sayHello = function(){ 
  7. alert ('hello'); 
  8. }; 
  9. // define the Student class 
  10. function Student() { 
  11. // Call the parent constructor 
  12. Person.call(this); 
  13. // inherit Person 
  14. Student.prototype = new Person(); 
  15. // correct the constructor pointer because it points to Person 
  16. Student.prototype.constructor = Student; 
  17. // replace the sayHello method 
  18. Student.prototype.sayHello = function(){ 
  19. alert('hi, I am a student'); 
  20. // add sayGoodBye method 
  21. Student.prototype.sayGoodBye = function(){ 
  22. alert('goodBye'); 
  23. var student = new Student(); 
  24. student.sayHello(); 
  25. student.walk(); 
  26. student.sayGoodBye(); 
  27. // check inheritance 
  28. alert(student instanceof Person); // true  
  29. alert(student instanceof Student); // true 

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

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

圖片精選

主站蜘蛛池模板: 吉木萨尔县| 赞皇县| 澜沧| 东阳市| 荣成市| 娄烦县| 巴中市| 平罗县| 柳州市| 缙云县| 霍州市| 射阳县| 施甸县| 内江市| 治县。| 新建县| 酉阳| 科尔| 美姑县| 文安县| 云安县| 江孜县| 河间市| 樟树市| 洛宁县| 吉首市| 玉树县| 巴里| 晴隆县| 星座| 威远县| 东山县| SHOW| 林芝县| 宜章县| 新河县| 肇州县| 河源市| 防城港市| 绥中县| 宜春市|