diff options
Diffstat (limited to 'tests/dom_tests/bind.js')
| -rw-r--r-- | tests/dom_tests/bind.js | 27 | 
1 files changed, 27 insertions, 0 deletions
| diff --git a/tests/dom_tests/bind.js b/tests/dom_tests/bind.js new file mode 100644 index 00000000..833f8006 --- /dev/null +++ b/tests/dom_tests/bind.js @@ -0,0 +1,27 @@ +/*  + * Polyfill taken from https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Function/bind + * Necessary because the current version of PhantomJS doesn't yet support bind(). + */ +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 && oThis +              ? this +              : oThis, +              aArgs.concat(Array.prototype.slice.call(arguments))); +        }; + +    fNOP.prototype = this.prototype; +    fBound.prototype = new fNOP(); + +    return fBound; +  }; +} | 
