Skip to content

Instantly share code, notes, and snippets.

@rikuba
Created September 28, 2013 11:51
Show Gist options
  • Save rikuba/6741315 to your computer and use it in GitHub Desktop.
Save rikuba/6741315 to your computer and use it in GitHub Desktop.
patch Function.prototype.apply LICENSE: CC0 <http://creativecommons.org/publicdomain/zero/1.0/>
(function () {
try {
Array.apply(null, {});
return;
} catch (e) { }
var toString = Object.prototype.toString,
arrayType = '[object Array]',
_apply = Function.prototype.apply,
slice = /*@cc_on @if (@_jscript_version <= 5.8)
function () {
var a = [], i = this.length;
while (i-- > 0) a[i] = this[i];
return a;
}@else@*/Array.prototype.slice/*@end@*/;
Function.prototype.apply = function apply(thisArg, argArray) {
return _apply.call(this, thisArg,
toString.call(argArray) === arrayType ? argArray : slice.call(argArray));
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment