-
Notifications
You must be signed in to change notification settings - Fork 5
/
immutable.js
44 lines (35 loc) · 806 Bytes
/
immutable.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
function copy(x){
var y = new x.constructor
for(var z in x)
if(x.hasOwnProperty(z))
y[z] = x[z]
return y
}
function O(a, b){
if(arguments.length == 1)
if(this instanceof O)
this.apply =
typeof a == 'function' ? a : function(b){
return O(b != null ? b : {}, a)
}
else
return new O(a)
else if(a == null)
return arguments.length > 2 ? O.call.apply(O, arguments) : b
else {
a = copy(a)
for(var i = 1; i < arguments.length; i++, b = arguments[i])
for(var key in b)
if(b.hasOwnProperty(key))
b[key] == O
? delete a[key]
: a[key] =
b[key] instanceof O
? b[key].apply(a[key])
: b[key]
return a
}
}
try {
module.exports = O
} catch(e) {}