Skip to content

Instantly share code, notes, and snippets.



Last active Dec 11, 2015
What would you like to do?
Inject method in CoffeSrcipt using JQuery
# inject function
inject = (collection, object, handler)->
$.each collection, (index, value)->
object = handler(object, value)
# the same as a method
inject_method = (object, handler)->
inject(this, object, handler)
# iterating over jquery object
$.fn.inject = inject_method
# iterating over arrays
if Array.prototype.inject = undefined
Array.prototype.inject = inject_method
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.