-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
Copy pathmixins.js
51 lines (51 loc) · 1.63 KB
/
mixins.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var Disposable = (function () {
function Disposable() {
}
Disposable.prototype.dispose = function () {
this.isDisposed = true;
};
return Disposable;
})();
var Activatable = (function () {
function Activatable() {
}
Activatable.prototype.activate = function () {
this.isActive = true;
};
Activatable.prototype.deactivate = function () {
this.isActive = false;
};
return Activatable;
})();
var ActivatibleDisposible = (function () {
Disposable.apply(this);
ActivatibleDisposible.apply(this);
return this;
});
var SmartObject = (function (_super) {
__extends(SmartObject, _super);
function SmartObject() {
var _this = this;
_super.call(this);
setInterval(function () { return console.log(_this.isActive + " : " + _this.isDisposed); }, 500);
}
SmartObject.prototype.interact = function () {
this.activate();
};
return SmartObject;
})(ActivatibleDisposible);
applyMixins(SmartObject, [Disposable, Activatable]);
var smartObj = new SmartObject();
setTimeout(function () { return smartObj.interact(); }, 1000);
function applyMixins(derivedCtor, baseCtors) {
baseCtors.forEach(function (baseCtor) {
Object.getOwnPropertyNames(baseCtor.prototype).forEach(function (name) {
derivedCtor.prototype[name] = baseCtor.prototype[name];
});
});
}