This came about after attempting to write the longest and most inefficient getElementById function I could.
http://github.com/psychcf/stupid
Feel free to fork it, add more functions, and make it better (or worse, depending on how you look at it).
This came about after attempting to write the longest and most inefficient getElementById function I could.
http://github.com/psychcf/stupid
Feel free to fork it, add more functions, and make it better (or worse, depending on how you look at it).
One Comment
you could make it slower
diff –git a/stupid.js b/stupid.js
index b339569..ace1a2b 100644
— a/stupid.js
+++ b/stupid.js
@@ -5,19 +5,21 @@ See README and LICENSE for more info. Docs are inline comments.
*/
stupid = {
byId: function(id){
- //Gets an element by it’s ID.
- var search = function(elem, id){
- if(elem.id == id){
- return elem;
- }
- var children = elem.childNodes;
- for(var i in children){
- if(res=search(children[i], id)){
- return res;
- }
- }
- }
- return search(document, id);
+ setTimeout(function() {
+ //Gets an element by it’s ID.
+ var search = function(elem, id){
+ if(elem.id == id){
+ return elem;
+ }
+ var children = elem.childNodes;
+ for(var i in children){
+ if(res=search(children[i], id)){
+ return res;
+ }
+ }
+ }
+ return search(document, id);
+ }, (3 * 1000));
},
wrapFunctions: function(obj, name){
//Wraps functions so that you can see their calls in firebug. ‘obj’ is either a function or object with functions. ‘name’ is an optional name.