[Javascript] Literal array declarations

Troy III Ajnej trojani2000 at hotmail.com
Mon Nov 9 01:51:10 CST 2009


To my knowlledge:
-No JavaScript reasons at all. That's how jslint author 
prefers it for himself.

Some years ago
anArray = []; //would mean nothing!
In fact it would most probably throw an error!
Array literals are introduced in javascript v1.2. Yet
IE claims to support them since v.1.1.

Using array literals instead of array objects whenever
possible, is a future precaution but backward incompatible
scripting convention. Its all because of JSON, since Array
object will act and might accidentaly trigger a premature
eval of your literal notations. And that's all there is
regarding this jslint remark. 

No real Javascript reasons sit behind this preferrence.
JSON is being considered a language today. But I dont 
see a convincing reason of why or how, when its nothing 
but a regular javascript Method. And as already mentioned 
available since JavaScript 1.2 to be used feelly by everyone.

p.s.:
Since IE8, JSON Object is natively supported in Explorer
providing: JSON.stringify; .toJSON(); and JSON.parse methods.
(JScript v5.8)

 

Regards

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                      Troy III
                         progressive art enterprise
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 



 
> From: philthathril at gmail.com
> Date: Thu, 29 Oct 2009 14:01:53 -0500
> To: javascript at lists.evolt.org
> Subject: [Javascript] Literal array declarations
> 
> Hi all.
> 
> I ran across http://www.jslint.com/ and had it evaluate my code. One 
> of the things it suggested was to "Use the array literal notation []." 
> So, I had:
> 
> var anArray = new Array();
> 
> and JSLint wants me to do:
> 
> var anArray = [];
> 
> Well, I'm curious... why is the literal declaration preferred?
> 
> Thanks,
> ~Philip
> _______________________________________________
> Javascript mailing list
> Javascript at lists.evolt.org
> http://lists.evolt.org/mailman/listinfo/javascript
 		 	   		  
_________________________________________________________________
Hotmail: Trusted email with Microsoft's powerful SPAM protection.
http://clk.atdmt.com/GBL/go/177141664/direct/01/
http://clk.atdmt.com/GBL/go/177141664/direct/01/



More information about the Javascript mailing list