[CoffeeScript] Polyfill for missing bind() in PhantomJS
Did receive unexplicable errors when running JS tests through Karma on a PhantomJS server, like: TypeError: 'undefined' is not a function (evaluating 'this.proxy[method].bind(this.proxy)') Looks like the problem is that PhantomJS is built with an old version of the JavaScript core where the bind method is not part of the Function prototype. There's a polyfill for that further down this page. That adds the method to the Function prototype. Here now is the same translated to CoffeeScript: if !Function::bind Function::bind = (oThis) -> if typeof @ != 'function' throw new TypeError 'Function.prototype.bind - what is trying to be bound is not callable' aArgs = [ Array::slice.call(arguments, 1), fToBind = this, fNOP = ->, fBound = -> ...