4 ms·
Good tips overall. I'd recommend a couple of changes though. "Don’t Touch the Doc (Unless You Have To)" This should say, "Don't Touch the DOM (Unless You Hav
by geuis 14y ago
Good tips overall.
I'd recommend a couple of changes though.
"Don’t Touch the Doc (Unless You Have To)"
This should say, "Don't Touch the DOM (Unless You Have To)". The reason is that it's almost never referred to as the Document, and always referred to as the DOM. If you have programmers new to js, they will find much more info when using the correct terminology. Since we're in the spirit of education, lets teach the right things.
I'd love to see this less in paragraph form and more in code form. Programmers are used to skimming through code. Eyes start wandering when having to extract programmer concepts from dense text. This is, of course, my own opinion and totally subjective.
- firefoxman1 14y agoOn that same note, as a performance tip I would expand it to "Cache your property lookups." Caching obj.property in a variable is much faster if you're going to reference it more than twice.
- gillespie 14y agoIs this still true on modern browsers with optimising js engines? And if so, why?
- firefoxman1 14y agoWell, according to this answer (http://stackoverflow.com/a/7701264 http://stackoverflow.com/a/7701264) V8 is about the same speed as accessing variables, however I would bet looking up properties higher up the prototype chain would take a performance hit.
- gillespie 14y agoI was thinking more that if you repeatedly access a property, regardless of where in the prototype chain it is, the optimiser would cache the value, so it would be equivalent to saving it in a local variable. If I'm not mistaken, this is a common feature in optimizing compilers. I don't know how aggressive the JIT js compilers are, however.
- firefoxman1 14y agoHmm that's pretty interesting. I don't really like to depend on the engine for optimizations because you never know what JS engine people have, but it's good to know they do that.