Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #29646
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: (Sort of) newbie trying to understand "array.length" |
| Date | 2016-02-21 23:48 +0100 |
| Organization | PointedEars Software (PES) |
| Message-ID | <2392050.Ox0AAuCGCL@PointedEars.de> (permalink) |
| References | <b99c7479-d78d-4e99-b6e7-c3e6d2010e6c@googlegroups.com> <array-20160221194511@ram.dialup.fu-berlin.de> |
Stefan Ram wrote:
> bit-naughty@hotmail.com writes:
>>Like, "array" is a reserved word which comes with the
>>system (Firefox or whatever), right?
>
> »array« is a MemberExpression, too. But it's also
> a PrimaryExpression this time. It may have a value.
An expression (including a /MemberExpression/) is evaluated to a value
instead. This happens by finding the best applicable production of the
grammar (the longest match usually wins), and executing the implementation
of the algorithm that is specified for that production. This may include
executing implementations of algorithms specified for other productions.
>>And "length" is a property of it?
>
> Yes, it's an identifier that names a possible property.
Grammatically, since ECMAScript Ed. 5 it is an Identifier Name
(/IdentifierName/), meaning that it may be a reserved word (/ReservedWord/)
which is not allowed for /Identifier/s:
<http://www.ecma-international.org/ecma-262/5.1/#sec-7.6>
<http://www.ecma-international.org/ecma-262/5.1/#sec-11.2>
<http://www.ecma-international.org/ecma-262/6.0/#sec-names-and-keywords>
<http://www.ecma-international.org/ecma-262/6.0/#sec-left-hand-side-expressions>
JSHint [1][2] can issue warnings if reserved words are used as property
names in dot property accessor syntax, and if the bracket property accessor
syntax instead of the dot property accessor syntax is used and the property
name is not a reserved word.
[1] <http://jshint.com/>
[2] Recommended: <https://atom.io/packages/linter-jshint>
>>ie. "array" is an object?
>
> It's a PrimaryExpression (an IdentifierReference [12.1]),
> whose value /can/ be an object, but whose value is not
> an object right after the start of Firefox:
>
> array
> ReferenceError: array is not defined
IOW, it is not the name of a variable or a built-in property of an object in
the scope chain in Mozilla JavaScript (unknown version), the version of the
implementation of ECMAScript that is supported by that version of Firefox.
>>Like, in BASIC
>
> BASIC
> ReferenceError: BASIC is not defined
Not funny.
>>*JS*, _why_ did they do things this way?
>
> In Java, it is done that way because Brendan Eich was told
^^^^^^^
> that JavaScript should look similar to Java.
Poorly worded; you have it partially backwards. Brendan Eich did not invent
Java, he invented JavaScript. JavaScript and other ECMAScript
implementations are that way because it was so in Java, not the other way
around.
> Java was designed to look familiar to C++ programmers,
Cite evidence.
> where it is written that way.
As “array” would/should hold a *reference* to an object in an ECMAScript
implementation and in Java, in C++ (and C) the equivalent syntax would be
the pointer-dereferencing “array->length” or “(*array).length” instead.
<http://stackoverflow.com/questions/13366083/why-does-the-arrow-operator-in-c-exist> p.
>>To *my* mind, array-dot-something should be what's INSIDE
>>that array, like a subscript, just like a dot after an object
>>literal ("x.d") means what's INSIDE that object literal, but
>>that's not what they did.....
>
> The »length« property is perceived to /be/ »inside« the
> »array« object, when someone writes »array.length«.
“array” is not an object; it is the name of a variable or property whose
value is a reference to an object at the time of successful identifier
resolution.
--
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
(Sort of) newbie trying to understand "array.length" bit-naughty@hotmail.com - 2016-02-21 09:51 -0800
Re: (Sort of) newbie trying to understand "array.length" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-02-21 23:48 +0100
Re: (Sort of) newbie trying to understand "array.length" Scott Sauyet <scott.sauyet@gmail.com> - 2016-02-25 06:24 -0800
Re: (Sort of) newbie trying to understand "array.length" John Harris <niam@jghnorth.org.uk.invalid> - 2016-02-22 11:03 +0000
Re: (Sort of) newbie trying to understand "array.length" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-02-22 12:23 +0000
Re: (Sort of) newbie trying to understand "array.length" Aleksandro <aleksandro@gmx.com> - 2016-02-22 11:57 -0300
Re: (Sort of) newbie trying to understand "array.length" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-02-22 21:19 +0100
Re: (Sort of) newbie trying to understand "array.length" "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-02-23 11:22 +0100
Re: (Sort of) newbie trying to understand "array.length" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-02-23 20:50 +0100
Re: (Sort of) newbie trying to understand "array.length" "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-02-23 11:20 +0100
csiph-web