Mercurial > eldonilo > lightstring
comparison lib/bind.js @ 103:5c6056f6da0a
Move polyfill.js to lib/bind.js
author | Sonny Piers <sonny.piers@gmail.com> |
---|---|
date | Tue, 12 Jun 2012 19:53:00 +0200 |
parents | polyfill.js@d9804e206393 |
children |
comparison
equal
deleted
inserted
replaced
102:4cb13828db73 | 103:5c6056f6da0a |
---|---|
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 } |