Live data from Hacker News

One page: Javascript in 10 minutes

javascript.infogami.com

11–19 of 19 posts

Re: One page: Javascript in 10 minutes

#11
post #3

Property Maps var emptyMap = {}; In JavaScript, these are called Objects. I don't think it's right for them to be called "property maps" in a tutorial like this. The heading called "Objects" should be renamed something like "Constructors" too. Also, using for (var i in array) is not the preferred way of iterating over an array (the for construct does not guarantee ordering).

for...in loops also have the drawback of iterating over inherited properties. eg if I extended the prototype of Array with some method, then for...in would iterate over that method too. traditional for loops incrementing until length is reached are preferable for arrays (personal style: for(var i=0,l=array.length ; i For objects, for...in with a hasOwnProperty check is preferred, I think (if you're going to be iterat…

  using an object as a textually-indexed array,
  which isn't that great
Using it as a hash table is just fine.

Re: One page: Javascript in 10 minutes

#12
post #11
post #3

Earlier quoted context omitted.

for...in loops also have the drawback of iterating over inherited properties. eg if I extended the prototype of Array with some method, then for...in would iterate over that method too. traditional for loops incrementing until length is reached are preferable for arrays (personal style: for(var i=0,l=array.length ; i For objects, for...in with a hasOwnProperty check is preferred, I think (if you're going to be iterat…

using an object as a textually-indexed array, which isn't that great Using it as a hash table is just fine.

Yes, my problem was with people then wanting to iterate over said hashmap, not with using it as a hashmap in the first place. I could have worded that better, thanks.

I mean if you're going to want to iterate over it, you should probably be using an array instead.

Re: One page: Javascript in 10 minutes

#14
I teach a series of classes about the web for designers, and this is a great start. It may not be perfect, but in terms of a basic intro to express common structures to anyone with a background in any other language (for example, my students all know php) it's a good summary, and an appropriate bare-bones jumping-off-point into more specific topics.

Re: One page: Javascript in 10 minutes

#15

Property Maps var emptyMap = {}; In JavaScript, these are called Objects. I don't think it's right for them to be called "property maps" in a tutorial like this. The heading called "Objects" should be renamed something like "Constructors" too. Also, using for (var i in array) is not the preferred way of iterating over an array (the for construct does not guarantee ordering).

The whole page disqualified itself instantly, not a single note about `hasOwnProperty` on the whole page :(

Re: One page: Javascript in 10 minutes

#16
post #9
post #7

Earlier quoted context omitted.

"... Don't do what Johnny Don't does. ..." Love that Simpson quote, "Boy-Scoutz 'n the Hood" S5E8 ~ http://en.wikipedia.org/wiki/Boy-Scoutz_%27n_the_Hood

Except it's actually "Donny Don't" :)

D'oh, my bad, you're right.

http://brammoblog.files.wordpress.com/2010/10/donny_dont_22....

Re: One page: Javascript in 10 minutes

#19
The first few lines are misleading - Javascript doesn't really have an integer type. At least for Ecmascript 5 http://www.ecma-international.org/publications/files/ECMA-ST... both integers and floats are stored as IEEE floats and the type is called Number. "Small enough" integers are stored exactly so this works well enough in practice.

(Despite this, it does have some functions for converting and parsing integral values.)

Ecmascript 4 (abandoned) had some support for an Integer type (it was a kind-of pseudo-type mess where the value of a Number was checked to see if it was an integer or not).

Post reply on HN