- /* Extend Function */
- function extend(subClass,superClass){
- var Func = function(){} ;
- Func.prototype = superClass.prototype ;
- subClass.prototype = new Func() ;
- subClass.prototype.constructor = subClass ;
- } ;
- /*-----Example-----*/
- /* Class Person */
- function Person(name){
- this.name = name ;
- } ;
- Person.prototype.getName = function(){
- return this.name ;
- } ;
- /* Class Author */
- function Author(name,books){
- Person.call(this,name) ;
- this.books = books ;
- } ;
- extend(Author,Person) ;
- Author.prototype.getBooks = function(){
- return this.books ;
- } ;
JavaScript实现继承---extend函数
最新推荐文章于 2024-07-26 09:48:00 发布