首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件开发 >

javascript设计方式 第四章

2012-08-07 
javascript设计模式 第四章继承?父类/* Mixin class. */var Mixin function() {}Mixin.prototype {se

javascript设计模式 第四章

继承

?

父类

/* Mixin class. */var Mixin = function() {};Mixin.prototype = {  serialize: function() {    var output = [];    for(key in this) {      output.push(key + ': ' + this[key]);    }    return output.join(', ');  }};augment(Author, Mixin);var author = new Author('Ross Harmes', ['JavaScript Design Patterns']);var serializedString = author.serialize();/* Augment function. */function augment(receivingClass, givingClass) {  for(methodName in givingClass.prototype) {     if(!receivingClass.prototype[methodName]) {      receivingClass.prototype[methodName] = givingClass.prototype[methodName];    }  }}/* Augment function, improved. */function augment(receivingClass, givingClass) {  if(arguments[2]) { // Only give certain methods.    for(var i = 2, len = arguments.length; i < len; i++) {      receivingClass.prototype[arguments[i]] = givingClass.prototype[arguments[i]];    }  }   else { // Give all methods.    for(methodName in givingClass.prototype) {       if(!receivingClass.prototype[methodName]) {        receivingClass.prototype[methodName] = givingClass.prototype[methodName];      }    }  }}
?

继承 ?耗费内存一些

原型 ?set 和 get 注意要统一

掺元 ?扩展类

?

?

热点排行