-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path050-FunctionExtensions.js
More file actions
52 lines (44 loc) · 1.48 KB
/
050-FunctionExtensions.js
File metadata and controls
52 lines (44 loc) · 1.48 KB
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
52
//console.debug("begin functionextensions.js");
//define a single reference for an empty function
if (typeof Function.empty == 'undefined')
Function.empty = function(){};
//EcmaScript 5 Function.prototype.bind
if (typeof Function.prototype.bind != "function")
Function.prototype.bind = function() {
var slice = Array.prototype.slice
,method = this
,args = slice.call(arguments)
,context = args.shift()
return function() {
method.apply(context, args.concat(slice.call(arguments)));
}
};
//JavaScript implementation of partial
if (typeof Function.prototype.partial == "undefined")
Function.prototype.partial = function() {
var slice = Array.prototype.slice
,method = this
,args = slice.call(arguments)
,partial = function() {
return method.apply(this, args.concat(slice.call(arguments)));
}
//override unpartial property to return original function
partial.unpartial = function() {
return method;
}
return partial;
};
//unpartial, when overriden gets a back reference to the original method used
if (typeof Function.prototype.unpartial != "function")
Function.prototype.unpartial = function() {
return this; //to be overriden by partial
}
//curry - use partial
if (typeof Function.prototype.curry != "function")
Function.prototype.curry = Function.prototype.partial;
//uncurry - return base function used.
if (typeof Function.prototype.uncurry != "function")
Function.prototype.uncurry = function() {
return this.unpartial();
}
//console.debug("end functionextensions.js");