最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JavaScript中繼承用法實(shí)例分析

 更新時(shí)間:2015年05月16日 09:11:59   作者:不吃皮蛋  
這篇文章主要介紹了JavaScript中繼承用法,以實(shí)例形式較為詳細(xì)的分析了javascript實(shí)現(xiàn)繼承的相關(guān)技巧,需要的朋友可以參考下

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

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

希望本文所述對(duì)大家的javascript程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

哈尔滨市| 吉木萨尔县| 莫力| 建瓯市| 霸州市| 麟游县| 新泰市| 边坝县| 兴仁县| 石柱| 南康市| 山阳县| 伽师县| 和顺县| 嘉荫县| 卓资县| 白沙| 平武县| 乐平市| 四子王旗| 颍上县| 合山市| 合作市| 张家界市| 永川市| 扎囊县| 呼和浩特市| 合阳县| 武冈市| 文化| 双流县| 潜江市| 二连浩特市| 乐都县| 盐池县| 泰来县| 天水市| 胶州市| 西乡县| 玉树县| 阳朔县|