JS设计模式源代码

源代码在线查看: 4.03 - the extend function.js

软件大小: 80 K
上传用户: BEIJINGHUANYING
关键词: 设计模式 源代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				/* Extend function. */								function extend(subClass, superClass) {				  var F = function() {};				  F.prototype = superClass.prototype;				  subClass.prototype = new F();				  subClass.prototype.constructor = subClass;				}												/* 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;				};																/* Extend function, improved. */								function extend(subClass, superClass) {				  var F = function() {};				  F.prototype = superClass.prototype;				  subClass.prototype = new F();				  subClass.prototype.constructor = subClass;								  subClass.superclass = superClass.prototype;				  if(superClass.prototype.constructor == Object.prototype.constructor) {				    superClass.prototype.constructor = superClass;				  }				}												/* Class Author. */								function Author(name, books) {				  Author.superclass.constructor.call(this, name);				  this.books = books;				}				extend(Author, Person);								Author.prototype.getBooks = function() {				  return this.books;				};								Author.prototype.getName = function() {				  var name = Author.superclass.getName.call(this);				  return name + ', Author of ' + this.getBooks().join(', ');				};							

相关资源