Skip to content

Instantly share code, notes, and snippets.

@minikomi
Created January 30, 2012 05:49
Show Gist options
  • Save minikomi/1702793 to your computer and use it in GitHub Desktop.
Save minikomi/1702793 to your computer and use it in GitHub Desktop.
Chaining using underscore
_({first: 1, second: 2, text: 'string here' }) // put object to wrapper
.chain() // chaining enabled
.compact() // now work with: [1,2, 'string here']
.size() // now: 3
.value() // return result

Using underscore.js "wrapper"

Calling underscore as a function will return a wrapped object. Calling chain() on the object allows you to chain subsequent functions.

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