Skip to content

Instantly share code, notes, and snippets.

Last active March 30, 2023 01:59
  • Star 34 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
JavaScript: call invo-cursion?
// OOP
console.log( 'OHAI'.blink() );
// Call invocation
console.log('OHAI') );
// $ always makes things look awesome.
var $ =;
// Very explicit call invocation
console.log( $.call(String.prototype.blink, 'OHAI') );
// Very, very explicit call invocation, ie. call invo-cursion?
console.log( $.call($,$,$,$,$,$,$,$,$,$,$,$, String.prototype.blink, 'OHAI') );
// ^^^^^^^^^^^^^^^^^^^^^^^ "bonus" calls
// You can have fun with apply invocation and _ too.
var _ = Function.prototype.apply;
// Very, very explicit apply invocation, ie. apply invo-cursion.
console.log( _.apply(_,[_,[_,[_,[_,[_,[_,[_, [ String.prototype.blink, ['OHAI'] ]]]]]]]]) );
// ^^^^^^^^^^^^^^^^^^^^^^ "bonus" applies, and fun w/brackets ^^^^^^^^
Copy link

haocong commented Sep 7, 2016

@jackocnr For the last FYI, I thought it would be like this: when you pass to, the is no longer an Object method, it is now just a simple function, with the call missing this then JavaScript runtime call an undefined function and will throw an error.

Array.apply(null, {length: 5}).map( // TypeError: undefined is not a function

For better understanding, here is another example:

var call =;
call() // TypeError: call is not a function, undefined, 1) // 1, undefined, 'foo') // foo

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