[Javascript] Literal array declarations
David Dorward
david at dorward.me.uk
Mon Nov 9 04:34:31 CST 2009
On 9 Nov 2009, at 07:51, Troy III Ajnej wrote:
> 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.
There is a long history of proprietary browser features being adopted
by the wider market and standardised. I suspect that is JScript 1.1
rather than JavaScript 1.1 though.
> Using array literals instead of array objects whenever
> possible, is a future precaution but backward incompatible
> scripting convention.
In general, there is no need to be backwards compatible to that degree.
> Its all because of JSON
No, it isn't.
It isn't part of the syntax because of JSON because JSON came later.
It isn't preferred because of JSON — other mails in this thread have
already explained the real reason.
> , 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.
What? Could you elaborate?
> No real Javascript reasons sit behind this preferrence.
No, there are real JavaScript reasons, they were explained elsewhere
in the thread. It isn't a requirement of the language, but the reasons
are based on how the language works.
> JSON is being considered a language today.
It's a data serialisation format. It is as much as language as XML
(which is to say, it is a language, but shouldn't be confused with a
programming language).
> But I dont
> see a convincing reason of why or how, when its nothing
> but a regular javascript Method.
It's a simple way to represent a complex data structure in text that
can be quickly parsed in JavaScript and has libraries available to
parse it in every major programming language (and a lot of other
programming languages which aren't considered major).
--
David Dorward
http://dorward.me.uk
More information about the Javascript
mailing list