Skip to content

Instantly share code, notes, and snippets.

@fakefarm
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fakefarm/fffd4b8da6464951ca19 to your computer and use it in GitHub Desktop.
Save fakefarm/fffd4b8da6464951ca19 to your computer and use it in GitHub Desktop.

JS return values chain well

Make an array

var a = []
=> []

And a function that returns the array

var b = function(){ return a }
=> function (){ return a }

Invoking the function will return an array

b()
=> []

Since an Array is the return value of that function, I can chain Array methods to the function

b().push(1)
=> 1

Moreso, that method actually influenced the a array;

a
=> [1]

Think of the possibilities...

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