Skip to content

Instantly share code, notes, and snippets.

@kensnyder
Created July 30, 2009 18:38
Show Gist options
  • Save kensnyder/158848 to your computer and use it in GitHub Desktop.
Save kensnyder/158848 to your computer and use it in GitHub Desktop.
// Prototype object that works a lot like jQuery:
var NodeList = Class.create(Enumerable);
Object.extend(NodeList.prototype, {
initialize: function(selector) {
this.elements = $$(selector);
},
_each: function(iterator) {
this.elements.each(iterator);
return this;
}
});
for (var methodName in Element.Methods) {
NodeList.prototype[methodName] = (function(methodName) {
return function() {
var args = Array.prototype.slice.call(arguments, 0);
this.elements.each(function(element) {
element[methodName].apply(element, args);
});
return this;
};
})(methodName);
}
// example usage
new NodeList('li').hide()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment