掺元类本质上是把一个函数的原型中包含的属性拷贝给另外一个函数的原型,使其包含指定的属性,并且这种方式在java里面并不存在。笔记如下:
function augent(receivingClass,givingClass){
if(arguments[2]){
for(var i=2,len=arguments.length;i<len;i++){
receivingClass.prototype[arguments[i]]=givingClass.prototype[arguments[i]];
}
}else{
for(methodName in givingClass.prototype){
if(!receivingClass.prototype[methodName]){
receivingClass.prototype[methodName]=givingClass.prototype[methodName];
}
}
}
}
function augent(receivingClass,givingClass){
if(arguments[2]){
for(var i=2,len=arguments.length;i<len;i++){
receivingClass.prototype[arguments[i]]=givingClass.prototype[arguments[i]];
}
}else{
for(methodName in givingClass.prototype){
if(!receivingClass.prototype[methodName]){
receivingClass.prototype[methodName]=givingClass.prototype[methodName];
}
}
}
}