Skip to content

Commit 4be1922

Browse files
committed
add bind polyfill
1 parent 030f0d7 commit 4be1922

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

scripts/system/libraries/utils.js

+28
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,34 @@
66
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
77
//
88

9+
if (!Function.prototype.bind) {
10+
Function.prototype.bind = function(oThis) {
11+
if (typeof this !== 'function') {
12+
// closest thing possible to the ECMAScript 5
13+
// internal IsCallable function
14+
throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
15+
}
16+
17+
var aArgs = Array.prototype.slice.call(arguments, 1),
18+
fToBind = this,
19+
fNOP = function() {},
20+
fBound = function() {
21+
return fToBind.apply(this instanceof fNOP
22+
? this
23+
: oThis,
24+
aArgs.concat(Array.prototype.slice.call(arguments)));
25+
};
26+
27+
if (this.prototype) {
28+
// Function.prototype doesn't have a prototype property
29+
fNOP.prototype = this.prototype;
30+
}
31+
fBound.prototype = new fNOP();
32+
33+
return fBound;
34+
};
35+
}
36+
937
vec3toStr = function(v, digits) {
1038
if (!digits) { digits = 3; }
1139
return "{ " + v.x.toFixed(digits) + ", " + v.y.toFixed(digits) + ", " + v.z.toFixed(digits)+ " }";

0 commit comments

Comments
 (0)