Skip to content

Instantly share code, notes, and snippets.

@gregpalaci
Created July 19, 2013 07:42
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save gregpalaci/6037410 to your computer and use it in GitHub Desktop.
Save gregpalaci/6037410 to your computer and use it in GitHub Desktop.
CoffeeScript Jquery better each loop
# Better each() for use with coffeescript
# 1. Wraps child in jquery object
# 2. Sets child first argument, so that fat-binding can be used.
# 3. Sets @ as well, for normal binds
jQuery.fn.loop = (block) ->
for i in @
element = jQuery(i)
res = block.call element, element
break if res == false
### USE
$('.photo').loop ->
@hide()
$('.thing').loop (thing) =>
thing.css
width: @width()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment