ziyuewang 发表于 2013-1-22 22:34:55

JavaScript实现继承---extend函数

/* 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 ;} ;
页: [1]
查看完整版本: JavaScript实现继承---extend函数