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
希望本文所述對大家的javascript程序設(shè)計(jì)有所幫助。
相關(guān)文章
DOM操作原生js 的bug,使用jQuery 可以消除的解決方法
下面小編就為大家?guī)硪黄狣OM操作原生js 的bug,使用jQuery 可以消除的解決方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-09-09javascript消除window.close()的提示窗口
有人問起,怎么去掉js調(diào)用window.close()時(shí)怎么去掉那可惡的提示,咋一看好像還真不好弄,IE的安全機(jī)制好像就不允許通過腳本關(guān)閉本頁面,但是IE好像可以允許js關(guān)閉彈出窗口,那我們是不是可以通過一定的技巧欺騙一下IE,繞過去呢。鼓搗了幾下,似乎還真可以做到2015-05-05Javascript獲取HTML靜態(tài)頁面參數(shù)傳遞值示例
獲取HTML靜態(tài)頁面參數(shù)傳遞值可以利用split函數(shù)來按參數(shù)切成數(shù)組、利用正則表達(dá)式來獲取,具體實(shí)現(xiàn)如下,感興趣的朋友可以參考下2013-08-08