Skip to content

Instantly share code, notes, and snippets.

@brianleroux
Created May 12, 2010 18:43
Show Gist options
  • Save brianleroux/398962 to your computer and use it in GitHub Desktop.
Save brianleroux/398962 to your computer and use it in GitHub Desktop.
alert.call.call.call.call.call.apply(function (a) {return a}, [1,2]) // 2
@jaredatron
Copy link

// this is just a really silly way of saying this
Function.prototype.call.apply(function (a) {return a}, [1,2])
// 2

// if this still seems weird to you. Consider this:
function logThisAndArgs(){ console.log(this, arguments); }

Function.prototype.call.apply(logThisAndArgs, [{'some':'object'},1,2,3,4])
// logs -> Object { some="object"} [1, 2, 3, 4]

// or this
Function.prototype.call.call(logThisAndArgs, {'some':'object'},1,2,3,4)
// logs -> Object { some="object"} [1, 2, 3, 4]

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