]> git.ipfire.org Git - thirdparty/bootstrap.git/commitdiff
add polyfil for bind for tether.js
authorJacob Thornton <jacobthornton@gmail.com>
Wed, 19 Aug 2015 00:06:17 +0000 (17:06 -0700)
committerJacob Thornton <jacobthornton@gmail.com>
Wed, 19 Aug 2015 00:06:17 +0000 (17:06 -0700)
js/tests/unit/phantom.js

index 3ed3b3ea37ad12f3ef4b24b9a17e1f8e335ce9c2..2791bd8414957fb31df285d6eb7f6ad33d4bd1d3 100644 (file)
   })
 
 }())
+
+
+// bind polyfill
+// shoutout mdn: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind#Polyfill
+
+if (!Function.prototype.bind) {
+  Function.prototype.bind = function(oThis) {
+    if (typeof this !== 'function') {
+      // closest thing possible to the ECMAScript 5
+      // internal IsCallable function
+      throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
+    }
+
+    var aArgs   = Array.prototype.slice.call(arguments, 1),
+        fToBind = this,
+        fNOP    = function() {},
+        fBound  = function() {
+          return fToBind.apply(this instanceof fNOP
+                 ? this
+                 : oThis,
+                 aArgs.concat(Array.prototype.slice.call(arguments)));
+        };
+
+    if (this.prototype) {
+      // native functions don't have a prototype
+      fNOP.prototype = this.prototype;
+    }
+    fBound.prototype = new fNOP();
+
+    return fBound;
+  };
+}