Skip to content

Commit

Permalink
Updates polyfills according to https://developer.mozilla.org/en-US/do…
Browse files Browse the repository at this point in the history
  • Loading branch information
c4milo committed Feb 5, 2014
1 parent e366e42 commit a459627
Showing 1 changed file with 17 additions and 42 deletions.
59 changes: 17 additions & 42 deletions lib/util.js
@@ -1,25 +1,19 @@
if (!Function.prototype.bind) {
/**
* Makes sure .bind exists (ES5)
* @return {Object} blah.
* @param {Object} oThis blah.
**/
Function.prototype.bind = function(oThis) {
//closest thing possible to the ECMAScript 5
//internal IsCallable function
if (typeof this !== 'function') {
throw new TypeError('Function.prototype.bind ' +
'- what is trying to be fBound is not callable');
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);
var fToBind = this;
var fNOP = function() {};
var fBound = function() {
return fToBind.apply(
this instanceof fNOP ? this : oThis || window,
aArgs.concat(Array.prototype.slice.call(arguments)));
};
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();
Expand All @@ -29,26 +23,7 @@ if (!Function.prototype.bind) {
}

if (!Array.isArray) {
/**
* Makes sure Array.isArray exists. (ES5)
**/
Array.isArray = (function() {
// save a reference built-in Object.prototype.toString
var builtInToString = Object.prototype.toString;

// save a reference to built-in Function.prototype.call
var builtInToCall = Function.prototype.call;

// requires a built-in bind function, not a shim
var callWithArgs = builtInToCall.bind(builtInToCall);

var argToString = function(o) {
return callWithArgs(builtInToString, o);
};

return function(o) {
return argToString(o) === '[object Array]';
};
})();
}

Array.isArray = function (vArg) {
return Object.prototype.toString.call(vArg) === "[object Array]";
};
}

0 comments on commit a459627

Please sign in to comment.