Last active
December 11, 2015 06:58
-
-
Save nirname/4563074 to your computer and use it in GitHub Desktop.
Inject method in CoffeSrcipt using JQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# inject function | |
inject = (collection, object, handler)-> | |
$.each collection, (index, value)-> | |
object = handler(object, value) | |
true | |
object | |
# 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