Path: csiph.com!weretis.net!feeder4.news.weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: Thomas 'PointedEars' Lahn Newsgroups: comp.lang.javascript Subject: Re: (Sort of) newbie trying to understand "array.length" Date: Sun, 21 Feb 2016 23:48:28 +0100 Organization: PointedEars Software (PES) Lines: 97 Message-ID: <2392050.Ox0AAuCGCL@PointedEars.de> References: Reply-To: Thomas 'PointedEars' Lahn Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8Bit X-Trace: solani.org 1456094909 32678 eJwFwYEBwCAIA7CXZNJSz0GQ/09Ygk1jhRN0DMaFXJx6dgOt+do+LWf0cWXurJqSXnTXtTg/IAsRoA== (21 Feb 2016 22:48:29 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Sun, 21 Feb 2016 22:48:29 +0000 (UTC) User-Agent: KNode/4.14.2 X-User-ID: eJwNxsEBwCAIA8CVwJAo49BS9h/B3usIud4dooLD+RuWqNIyP3UIKQY96VPf425otWr3bMKK2VyApY6pgxc2+hRw Cancel-Lock: sha1:V0WdlGbMuC5dfqvzJuD/zDq2CH4= X-NNTP-Posting-Host: eJwFwQkBwDAIA0BLNPxyRjr8S+ida5xgWniYr2+Q+KaJurYhw8S4GDGyuSr/rYFUn20FeR4qNBFS Xref: csiph.com comp.lang.javascript:29646 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: 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] [2] Recommended: >>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. 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: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not cc me. / Bitte keine Kopien per E-Mail.