3 ms·
Yes, all that, plus readability. I know when something is a variable. Prefixing variables in JS with $ doesn't do this because I still have to look out for thin
by WilliamLP 16y ago
Yes, all that, plus readability. I know when something is a variable. Prefixing variables in JS with $ doesn't do this because I still have to look out for things without a $ that are variables as well so it's the worst of all worlds.
> (Aside: $ prefix is handy in JS when holding references to jQuery objects ie $container = $('#container');)
I really really don't want to see that in a project I'm in charge of. It looks terrible to me, and I really don't like $ as an ordinary alphanumeric character. I like $ in jQuery projects to only be used for jQuery calls. (If it doesn't have to co-exist with something else and use noConflict mode.)
> var user = {name: "Foo", dir: "foo"};
I hate that about Javascript, how in object literals the left side is a literal string and the right side is an expression. Except, I really should quote the left side anyway - I think Crockford recommends this - because I might want a hyphen in there, or I might want to use a keyword (like "interface" where it isn't even obvious that it actually is a keyword.)
Also, if I have var key, and var value, I want to be able to pass it into a function that takes a dictionary argument as {key: value}, and not have to do var dict={}; dict[key]=value;
I also think Javascript absolutely begs for a real dictionary type. Objects don't work so well because I have to worry about someone extending them and I have to use hasOwnProperty - never mind someone could override hasOwnProperty. Also the performance characteristics of JS objects are terrible - Did you know that in Firefox a switch statement is one hundred times faster than an object lookup?
PHP's dual purpose variables are ugly as hell (with object -> syntax and array [] syntax) but I actually like being clear on whether I'm using it as an object or a simple array/dictionary.
- wingo 16y ago> Did you know that in Firefox a switch statement is one hundred times faster than an object lookup? A switch statement in what language? I presume by "object lookup" you mean the "bar" in "foo.bar" in javascript. With all respect, I think you are worrying too much :)
- WilliamLP 16y ago> A switch statement in what language? Javascript. > I presume by "object lookup" you mean the "bar" in "foo.bar" in javascript. Yes, but more specifically what I tested was the foo[bar] form, where bar contains a string, versus switch(bar). > With all respect, I think you are worrying too much :) For a language that is supposed to be nearly ready for writing rich interactive applications including pixel-by-pixel manipulation, two orders of magnitude (and widely variable across browsers) is a huge deal. I'm guessing you haven't tried to do much canvas programming?