Skip to content

Instantly share code, notes, and snippets.

@cowboy
Last active March 30, 2023 01:59
Show Gist options
  • Star 34 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save cowboy/4477847 to your computer and use it in GitHub Desktop.
Save cowboy/4477847 to your computer and use it in GitHub Desktop.
JavaScript: call invo-cursion?
// OOP
console.log( 'OHAI'.blink() );
// Call invocation
console.log( String.prototype.blink.call('OHAI') );
// $ always makes things look awesome.
var $ = Function.prototype.call;
// 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 ^^^^^^^^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment