4.08 - the augment function.js

来自「JS设计模式源代码」· JavaScript 代码 · 共 27 行

JS
27
字号
/* 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];      }    }  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?