forked from aaditmshah/augment
-
Notifications
You must be signed in to change notification settings - Fork 0
/
augment.js
35 lines (30 loc) · 1.13 KB
/
augment.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
(function (global, factory) {
if (typeof define === "function" && define.amd) define(factory);
else if (typeof module === "object") module.exports = factory();
else global.augment = factory();
}(this, function () {
"use strict";
var Factory = function () {};
var slice = Array.prototype.slice;
var augment = function (base, body) {
var uber = Factory.prototype = typeof base === "function" ? base.prototype : base;
var prototype = new Factory;
body.apply(prototype, slice.call(arguments, 2).concat(uber));
if (!prototype.hasOwnProperty("constructor")) return prototype;
var constructor = prototype.constructor;
constructor.prototype = prototype;
return constructor;
};
augment.defclass = function (prototype) {
var constructor = prototype.constructor;
constructor.prototype = prototype;
return constructor;
};
augment.extend = function (base, body) {
return augment(base, function (uber) {
for (var key in body) this[key] = body[key];
this.uber = uber;
});
};
return augment;
}));