Created
September 24, 2012 22:45
-
-
Save talsafran/3778911 to your computer and use it in GitHub Desktop.
jQuery selector scoping technique using currying
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
<html> | |
... | |
<body class="<%= "#{params[:controller]} #{params[:action]}" %>"> | |
... | |
</body> | |
</html> |
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
// lib/jquery_extensions.js | |
var setSelectorContext = function(container) { | |
return function(query) { | |
return $(container).find(query) | |
} | |
} | |
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
// app/assets/javascripts/user.js | |
$(function() { | |
var $$$ = setSelectorContext('.users.index') | |
$$$('.profile') == $('.users.index .profile') // returns true | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment