Skip to content

Instantly share code, notes, and snippets.

@amiel
Created February 22, 2010 19:44
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 amiel/311412 to your computer and use it in GitHub Desktop.
Save amiel/311412 to your computer and use it in GitHub Desktop.
$.with_scope = function(scope, callback) {
var $scope = $(scope),
jquery_proxy = function(selector, context) { return $scope.find(selector, context); };
return callback(jquery_proxy);
};
// -- or --
$.fn.as_scope = function(callback) {
var self = this, jquery_proxy = function(selector, context) { return self.find(selector, context); };
return callback(jquery_proxy);
};
// examples
$.with_scope('#post_15', function($) {
$('.comments').hide();
});
$('#post_15').as_scope(function($) {
$('.comments').hide();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment