On Jul 13, 12:27 pm, David Marrs <[email protected]> wrote:
> > 1) I ALWAYS avoid use of object literals with only one exception.
> > Object literals are the slowest containers in JavaScript, so therefore
> > fast programs do not use them.
>
> I don't disagree with this in principle, but I made no effort to avoid
> using object literals in the app that I've just finished, and the app
> is as fast as you like. The only place I can see this being
> significant is if you're chugging through an iterator, or something.
It is significant if you have to loop through the contents of the
object, such as using a for loop. If the contents of the object have
be concatenated then it will certainly be slower than using an array
with a join method. The value of object literals is that their keys
are named values opposed to only 0 and positive integers like with
arrays. That value is certainly beneficial to people who have to
write code, but it is of no benefit to automation.
> > 2) I ALWAYS use a single var keyword per function and put it near the
> > top of the function.
>
> var foo, bar; baz;
>
> Can you see the mistake?
>
> var foo;
> var bar;
> var baz;
>
> Explicit, and a typo will result in a syntax error at worst.
If you are in strict mode then your application will break and a
debugger will point to that exact error. As a result I am not
concerned about this. If this something to be concerned about then
use JSLint or JSHint.
> > 3) I ALWAYS use anonymous functions assigned to variables.
>
> var foo = function() {
> return bar();
>
> }
>
> var bar = function() {
> return "hello";
>
> }
>
> calling foo() will result in an error because bar has been hoisted but
> not defined yet.
Correct. That is why I use assigned anonymous functions to circumvent
hoisting.
> function foo() {
> return bar();
>
> }
>
> function bar() {
> return "hello";
>
> }
>
> This time bar is defined and calling foo will work. Also, I find the
> latter easier to read.
Then we are at a difference of opinion. At troubleshooting time I
would prefer to quickly identify where "foo" and "bar" from your
example are defined without sifting through other keywords.
Austin Cheney, CISSP
http://prettydiff.com/
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]