comparison polyfill.js @ 85:d9804e206393

Fix Safari/iOS support.
author Sonny Piers <sonny.piers@gmail.com>
date Wed, 08 Feb 2012 17:44:06 +0100
parents
children
comparison
equal deleted inserted replaced
84:7f4e43d6cb15 85:d9804e206393
1 //js-core doesn't support bind, polyill taken from https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/bind
2 if (!Function.prototype.bind) {
3 Function.prototype.bind = function (oThis) {
4 if (typeof this !== "function") {
5 // closest thing possible to the ECMAScript 5 internal IsCallable function
6 throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
7 }
8
9 var aArgs = Array.prototype.slice.call(arguments, 1),
10 fToBind = this,
11 fNOP = function () {},
12 fBound = function () {
13 return fToBind.apply(this instanceof fNOP
14 ? this
15 : oThis || window,
16 aArgs.concat(Array.prototype.slice.call(arguments)));
17 };
18
19 fNOP.prototype = this.prototype;
20 fBound.prototype = new fNOP();
21
22 return fBound;
23 };
24 }