Forked from jswhisperer/CoffeeScript Jquery better each loop
Created
August 20, 2014 02:40
-
-
Save esshka/42a554a6d3cfed3c3310 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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