Skip to content

Instantly share code, notes, and snippets.

@broofa
Forked from joestelmach/gist:1098911
Created July 22, 2011 06:53
Show Gist options
  • Save broofa/1099000 to your computer and use it in GitHub Desktop.
Save broofa/1099000 to your computer and use it in GitHub Desktop.
apply: (Prototype.Browser.IE ? function(o, a) {
a = a || [];
switch (a.length) {
case 0: return this.call( o);// \ "FUUU...!"
case 1: return this.call( o,a[0]);// \ _
case 2: return this.call( o,a[0],a[1]);// \ \o
case 3: return this.call( o,a[0],a[1],a[2]);// /\_
case 4: return this.call( o,a[0],a[1],a[2],a[3]);// \ /\
case 5: return this.call( o,a[0],a[1],a[2],a[3],a[4]);// > /
case 6: return this.call( o,a[0],a[1],a[2],a[3],a[4],a[5]);// >
case 7: return this.call(o,a[0],a[1],a[2],a[3],a[4],a[5],a[6]);// \
}
return this._apply(o, a);
} : Function.prototype.apply),
@broofa
Copy link
Author

broofa commented Jul 22, 2011

I mean, if you need more than 7 arguments, you're code is pretty fucked anyway ...

@jdalton
Copy link

jdalton commented Jul 22, 2011

no need to ua sniff amiright? what's this for?

@broofa
Copy link
Author

broofa commented Jul 22, 2011

just riffing on https://gist.github.com/1099000/02cd631cb52ab159e5085c82cf8e14b5a164332f

Don't recall the original rational for the ua sniff. either early versions of IE didn't support apply(), or they weren't performant .vs. call().

@willbailey
Copy link

As I recall this was the solution to a weird error we encountered with cross-window js invocation in ie7.

@jdalton
Copy link

jdalton commented Jul 22, 2011

Smth like:

var args = [].slice.call(arguments);
args.unshift(o);
this.call.apply(this, args); // efff ya

efff ya

@broofa
Copy link
Author

broofa commented Jul 22, 2011

apply() method didn't exist pre IE5.5 I believe. wrote that code circa 2006-2007.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment