Hacker News new | past | comments | ask | show | jobs | submit login

Maybe I don't understand your use case, but it seems to me your function is masking some other problems. You say you're new to JS, so here's a little unsolicited advice...

If you find yourself retyping the same jQuery selectors over and over, or that the structure changes a lot, then you should be encapsulating that somehow into some other function or object. Instead you're writing a do-it-all function that takes more strokes to type than the original jQuery selectors!

I haven't seen the structure in question, but when I see a class called something very generic like "node", I suspect something else is wrong. If the class isn't specific and at least somewhat meaningful to a person, then you might be solving the problem at the wrong level, using classes when a rethink of the structure might be better.

Also... lack of semicolons is bad style. Lack of braces for if clauses is bad style. Fix it, you'll thank me later. :)




"Also... lack of semicolons is bad style. Lack of braces for if clauses is bad style. Fix it, you'll thank me later. :)"

Although a popular opinion, it's still just an opinion -- one I strongly disagree with. Almost all semicolon problems in javascript are not caused by not using them, they're caused by not understanding when they will be inserted. The infamous example:

  function func(param, param2) {
    var meh = 0, gah = 0;

    <some more logic here>;

    return
      { meh: meh
      , gah: gah
      };
   }
Note: using a semicolon did not save you from returning undefined.

My point is that whether you use or don't use semicolons is not the problem. Not understanding when and how they're inserted is the problem.

I also find that people who do not use semicolons have a much better understanding of the few situations where they are actually needed to avoid errors.


> you should be encapsulating that somehow into some other function or object

Hmm, I believe that's what I'm doing here. This pattern is nice because it's small, simple and easily applied anywhere.

> when I see a class called something very generic like "node"

This is for http://taskranger.com Node is a node in the tree. Might make more sense knowing that.

> lack of semicolons is bad style. Lack of braces for if clauses is bad style.

I'm aware of the consensus, but I'm pretty sure it's wrong :) Semicolons and unnecessary braces create noise and take up space. This subtly harms readability. I've been doing this for about a year and have had no problems.

I do appreciate the suggestions, though.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact

Search: