function MyClass() {
SuperClass.call(this);
OtherSuperClass.call(this);
}
MyClass.prototype = Object.create(SuperClass.prototype); //inherit
mixin(MyClass.prototype, OtherSuperClass.prototype); //mixin
MyClass.prototype.myMethod = function() {
// do a thing
};
这个代码 mixin不是很懂
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
Mixin是JavaScript中用的最普遍的模式,几乎所有流行类库都会有Mixin的实现。Mixin是掺合,混合,糅合的意思,即可以就任意一个对象的全部或部分属性拷贝到另一个对象上。
mixin(MyClass.prototype,OtherSuperClass.prot
otype); 就是将OtherSuperClass的原型拷贝到MyClass的原型上。