I just wrote this.



  • I don't know whether to be proud or ashamed.

    (Slightly modified from the actual code to protect the innocent... namely me.)

    var value = null;
    for (var node = document.getElementById(someId);
    	!(value = node.getAttribute("someAttribute")) && node.nodeName != "stopAtThisNode";
    	node = node.parentNode) {};
    
    if (!value) { /* etc */


  • @The MAZZTer said:

    abuse of for loops
    never heard of "while" loops then, eh? What you're doing is basically the same as you could do with a "while" loop, but less readable. (Since the two loops are basically the same thing anyway, just with syntax that makes more sense in different circumstances.)



  • I actually did it with a while loop first and then realized I was essentially just doing an empty for loop. :P

    You could do all for loops in while loops if you really want to (you have to if you use mIRC script, I really which khaled would implement a /for command).



  • @TarquinWJ said:

    @The MAZZTer said:
    abuse of for loops
    never heard of "while" loops then, eh? What you're doing is basically the same as you could do with a "while" loop, but less readable. (Since the two loops are basically the same thing anyway, just with syntax that makes more sense in different circumstances.)

    But it looks so much more clever this way!



  •  Why is it so hard to resist the urge to explain why you'd use a for loop versus a while loop?

     

    WHY SO DIFFICULT!?

     

    (Yes, it's been one of those weeks.)

    (Bonus imaginary points for identifying the esoteric quote!)



  •  You do realize you could do that with two simple function calls in jQuery?



  • This is for a commercial project. Plus we are near delivery so even if it is ok as far as licensing, not a good idea to add another library right now. :)

    I have been looking into learning jQuery for my personal usage though. Looks far easier than standard DOM functions.



  • @The MAZZTer said:

    [jQuery] far easier than standard DOM functions.
     

    It is fucking awesome.



  • @dhromed said:

    It is fucking awesome.
    Hur hur, your mom is awesome.



  • @dhromed said:

    @The MAZZTer said:

    [jQuery] far easier than standard DOM functions.
     

    It is fucking awesome.

    jQuery killed my mother while Prototype watched and laughed.  YUI just stared into space and drooled.  MooTools sat in the corner fingerbanging itself.


  • @The MAZZTer said:

    This is for a commercial project. Plus we are near delivery so even if it is ok as far as licensing, not a good idea to add another library right now. :)

    I have been looking into learning jQuery for my personal usage though. Looks far easier than standard DOM functions.


    Not only have I written pretty much that exact code before, I've even made a function for it (so you can pass in the attribute you're looking for, and the value you expect.)

    Of course, we install JS code on third-party sites we have no control over.



  • @bstorer said:

    jQuery killed my mother while Prototype watched and laughed.  YUI just stared into space and drooled.  MooTools sat in the corner fingerbanging itself.
     

    This is entirely plausible.

    I envision  MooTools as a hot chick, of course.



  • @The MAZZTer said:

    I don't know whether to be proud or ashamed.

     

     

    To this day, I still am proud of  this.



  • @TarquinWJ said:

    @The MAZZTer said:
    abuse of for loops
    never heard of "while" loops then, eh? What you're doing is basically the same as you could do with a "while" loop, but less readable.
     

     But... all C-style for loops are just while loops with weird, less readable syntax!  How is this any different?


Log in to reply