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

JavaScript中繼承用法實例分析

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

本文實例分析了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

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

相關(guān)文章

最新評論

岑巩县| 阳山县| 花垣县| 永年县| 永顺县| 濉溪县| 乐业县| 涿州市| 元谋县| 麟游县| 横峰县| 铅山县| 昌宁县| 景宁| 罗源县| 渭源县| 宿迁市| 拉萨市| 江山市| 夏邑县| 文成县| 齐河县| 虎林市| 故城县| 阿克苏市| 周宁县| 中阳县| 本溪市| 壶关县| 高邑县| 册亨县| 郴州市| 陵川县| 班戈县| 虹口区| 桑日县| 吉安市| 贡觉县| 长治县| 龙州县| 海晏县|