my favorite

2011/05/17

contradiction of javascript

By reading Javascript Patterns (by Stoyan Stefanov)

> var a = NaN;
undefined
> a.constructor
function Number() { [native code] }

it's so weird that NaN's constructor is in Number type.

> var a = new Array(1, 2, 3);
undefined
> a
[1, 2, 3]
> var b = new Array(1);
undefined
> b
[]

By using Array constructor w/ only one argument, it's array length, not first element.
Conclusion: using Array literal instead of Array constructor

1 comment:

RAMALAN JITU SGP/HKG said...

http://wwwuang47.blogspot.co.id/

BIO

Taipei, GuTing, Taiwan

huang47 | personal

huang47 | personal