address standardization UI, part 1
[freeside.git] / httemplate / elements / polyfill.js
1 // Function.bind(), not supported in IE8
2 // polyfill from Mozilla Developer Network
3
4 if (!Function.prototype.bind) {
5   Function.prototype.bind = function(oThis) {
6     if (typeof this !== 'function') {
7       // closest thing possible to the ECMAScript 5
8       // internal IsCallable function
9       throw new TypeError('Function.prototype.bind - what is trying to be bound is not callable');
10     }
11
12     var aArgs   = Array.prototype.slice.call(arguments, 1),
13         fToBind = this,
14         fNOP    = function() {},
15         fBound  = function() {
16           return fToBind.apply(this instanceof fNOP
17                  ? this
18                  : oThis,
19                  aArgs.concat(Array.prototype.slice.call(arguments)));
20         };
21
22     if (this.prototype) {
23       // native functions don't have a prototype
24       fNOP.prototype = this.prototype; 
25     }
26     fBound.prototype = new fNOP();
27
28     return fBound;
29   };
30 }