-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbind-slice.js
More file actions
40 lines (36 loc) · 898 Bytes
/
bind-slice.js
File metadata and controls
40 lines (36 loc) · 898 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
'use strict';
module.exports = function(boundThis) {
var f = this
, ret
if (arguments.length < 2)
ret = function() {
if (this instanceof ret) {
var ret_ = f.apply(this, arguments)
return Object(ret_) === ret_
? ret_
: this
}
else
return f.apply(boundThis, arguments)
}
else {
var boundArgs = new Array(arguments.length - 1)
for (var i = 1; i < arguments.length; i++)
boundArgs[i - 1] = arguments[i]
ret = function() {
var args = boundArgs.slice()
for (var i = 0; i < arguments.length; i++)
args.push(arguments[i])
if (this instanceof ret) {
var ret_ = f.apply(this, arguments)
return Object(ret_) === ret_
? ret_
: this
}
else
return f.apply(boundThis, args)
}
}
ret.prototype = f.prototype
return ret
}