-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMOP.js
More file actions
43 lines (36 loc) · 988 Bytes
/
MOP.js
File metadata and controls
43 lines (36 loc) · 988 Bytes
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
MOP = {
Class: function()
{
var mixins = [], methods = {}, base = null, init = null
function mixin(a, b) {
Object.keys(b).forEach(function(k) {
Object.defineProperty(a, k, Object.getOwnPropertyDescriptor(b, k))
})
}
Array.prototype.forEach.call(arguments, function(a) {
if (a instanceof Function) {
if (!base) {
base = a
} else {
mixins.push(a)
}
} else {
mixin(methods, a)
}
})
base = base || Object
if (methods.constructor == Object)
methods.constructor = function() { base.apply(this, arguments) }
init = methods.constructor
init.prototype = Object.create(base.prototype)
mixins.map(function(m) { mixin(init.prototype, m.prototype) })
mixin(init.prototype, methods)
init.new = function() {
var o = Object.create(init.prototype)
init.apply(o, arguments)
return o
}
init.super = base
return init
}
}