Created
July 30, 2009 18:38
-
-
Save kensnyder/158848 to your computer and use it in GitHub Desktop.
This file contains 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
// 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