Skip to content

Instantly share code, notes, and snippets.

@talsafran
Created September 24, 2012 22:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save talsafran/3778911 to your computer and use it in GitHub Desktop.
Save talsafran/3778911 to your computer and use it in GitHub Desktop.
jQuery selector scoping technique using currying
<html>
...
<body class="<%= "#{params[:controller]} #{params[:action]}" %>">
...
</body>
</html>
// lib/jquery_extensions.js
var setSelectorContext = function(container) {
return function(query) {
return $(container).find(query)
}
}
// 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