52 lines
1.4 KiB
JavaScript
52 lines
1.4 KiB
JavaScript
(function() {
|
|
var ExcludedClassProperties, ExcludedPrototypeProperties, Mixin, name;
|
|
|
|
module.exports = Mixin = (function() {
|
|
Mixin.includeInto = function(constructor) {
|
|
var name, value, _ref;
|
|
this.extend(constructor.prototype);
|
|
for (name in this) {
|
|
value = this[name];
|
|
if (ExcludedClassProperties.indexOf(name) === -1) {
|
|
if (!constructor.hasOwnProperty(name)) {
|
|
constructor[name] = value;
|
|
}
|
|
}
|
|
}
|
|
return (_ref = this.included) != null ? _ref.call(constructor) : void 0;
|
|
};
|
|
|
|
Mixin.extend = function(object) {
|
|
var name, _i, _len, _ref, _ref1;
|
|
_ref = Object.getOwnPropertyNames(this.prototype);
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
name = _ref[_i];
|
|
if (ExcludedPrototypeProperties.indexOf(name) === -1) {
|
|
if (!object.hasOwnProperty(name)) {
|
|
object[name] = this.prototype[name];
|
|
}
|
|
}
|
|
}
|
|
return (_ref1 = this.prototype.extended) != null ? _ref1.call(object) : void 0;
|
|
};
|
|
|
|
function Mixin() {
|
|
if (typeof this.extended === "function") {
|
|
this.extended();
|
|
}
|
|
}
|
|
|
|
return Mixin;
|
|
|
|
})();
|
|
|
|
ExcludedClassProperties = ['__super__'];
|
|
|
|
for (name in Mixin) {
|
|
ExcludedClassProperties.push(name);
|
|
}
|
|
|
|
ExcludedPrototypeProperties = ['constructor', 'extended'];
|
|
|
|
}).call(this);
|