Skip to content

Instantly share code, notes, and snippets.

@struys
Created June 25, 2014 17:15
Show Gist options
  • Save struys/1119dde414f0c2b079ba to your computer and use it in GitHub Desktop.
Save struys/1119dde414f0c2b079ba to your computer and use it in GitHub Desktop.
jlatt <3
/**
* .-´¯¯¯`-.
* ,´ `.
* | JLATT \
* \ _ \
* ,\ _ ,´¯,/¯)\
* ( q \ \,´ ,´ ,´¯)
* `._,) -´,-´)
* \/ ,´/
* ) / /
* / ,´-´
* IE8's console object is not a true Javascript object. Its functions do not
* inherit from Function.prototype and therefore call() and apply() cannot be
* used on it. The only option for apply-like behavior is to (you guessed it!)
* have specific code for each argument list. We truncate at ten arguments
* because, well, you shouldn't even be calling a function with that many.
*/
yelp.util.pseudoAppliers = [
function(func, args) {
func(args[0]);
},
function(func, args) {
func(args[0], args[1]);
},
function(func, args) {
func(args[0], args[1], args[2]);
},
function(func, args) {
func(args[0], args[1], args[2], args[3]);
},
function(func, args) {
func(args[0], args[1], args[2], args[3], args[4]);
},
function(func, args) {
func(args[0], args[1], args[2], args[3], args[4], args[5]);
},
function(func, args) {
func(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
},
function(func, args) {
func(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7]);
},
function(func, args) {
func(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8]);
},
function(func, args) {
func(args[0], args[1], args[2], args[3], args[4], args[5], args[6], args[7], args[8], args[9]);
}
];
yelp.util.pseudoApply = function(func, args) {
return yelp.util.pseudoAppliers[Math.min(args.length, yelp.util.pseudoAppliers.length) - 1](func, args);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment