ANTON072
2/25/2015 - 3:49 PM

mixin関数

mixin関数

function augment(receivingClass, givingClass){
  // 特定のメソッドだけを提供
  if ( auguments[2] ){
    for (var i = 2, len = aruguments.length; i < len; i++){
      receivingClass.prototype[arguments[i]] = givingClass.prototype[arguments[i]];
    }
  }
  // すべてのメソッドを提供
  else {
    for (var methodName in givingClass.prototype){
      if ( !Object.hasOwnProperty( receivingClass.prototype, methodName ) ) {
        receivingClass.prototype[methodName] = givingClass.prototype[methodName];
      }
    }
  }
}