Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #24815
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: "i = i|0" |
| Date | 2014-06-13 12:12 +0200 |
| Organization | PointedEars Software (PES) |
| Message-ID | <2714661.LRbm3SKrxb@PointedEars.de> (permalink) |
| References | (12 earlier) <20140612134628.144@kylheku.com> <2151521.roT7KvbrzH@PointedEars.de> <lndhoh$3qh$1@dont-email.me> <6de08f5b-6447-4394-9717-e15ccca7e175@googlegroups.com> <JavaScript-20140613034355@ram.dialup.fu-berlin.de> |
Stefan Ram wrote:
> "Michael Haufe (TNO)" <tno@thenewobjective.com> writes:
>> The very fact that Wikipedia and Stack Overflow are being
>> used as instruments of truth in this matter is slightly
>> disturbing.
>
> In this newsgroup, I deem relevant the MDN, which says:
(Again you have neglected to give proper reference. *Where* *exactly* on
MDN have you read what you quoted? You are, at least by appearance, at
least an aspiring scientist; you should know better than this [especially as
I told you several times before].)
MDN (Mozilla Developer Network) certainly is relevant; but it is a wiki as
well. It was _not_ solely written by the people developing *Mozilla*
JavaScript [0] (which is what [MDN] describes), so it cannot be
authoritative in any way. The validity of the statements in it depend on
the knowledge and experience of the people editing it, the time they can
invest in doing that, and the diligence they can show. (Me included.)
So, unsurprisingly, some invented terminology, and misleading, even
fundamentally wrong statements can still be found there. What you quoted is
a good example of that:
> »JavaScript's dynamic capabilities include runtime
> object construction,
True; you can create new objects at runtime that can have properties that
have not previously been defined:
var foo = {
bar: 42
};
// …
foo[some_variable_value] = some_other_variable_value;
> variable parameter lists,
No, in the ECMAScript terminology ([ES] §13), JavaScript parameter lists are
_not_ variable: it is not possible to change the name or number of formal
parameters of a function at runtime without creating a new function (and
even that is error-prone, see below).
However, the length of *argument* lists of function *calls* ([ES] §§11.2.3
and 11.2.4) is: in general, you can pass more or less arguments to in a
function call than the function has formal parameters, and you can access
those arguments using the “arguments” object in function context. In this
sense, the term “function” applies also to methods, properties of objects
whose value is a reference to a callable object. But the method may throw
an exception or return an error value if an unsupported number of arguments
was passed. Some methods of built-in objects throw exceptions in that case
[ES], many methods of host objects do (e.g., those specified in [DOM]).
> function variables,
What is a “function variable”? Neither the original JavaScript
documentation ([DevEdge]) nor [ES] define this term. It appears to be an
ad-hoc invention at MDN.
It is correct to say that functions are first-class objects in ECMAScript
implementations, including Mozilla JavaScript, in the sense that they can be
both l-values and r-values. In that sense, in
var f = function () {};
where (a reference to) a function is an r-value, “f” could be defined as
being a “function variable”; but that is a very limited view of this
language feature. For example, you can pass a reference to a function to
another function or even the same function:
function f (f2)
{
/* something */
}
f(f);
Here, “f” is _not_ a variable, it is a function name which becomes the name
of a property of the global object; “f2” also is _not_ a variable, it is
(the name of) a formal parameter of the function named “f”.
And, does “f” cease to be a “function variable” when, as there is only
dynamic type-checking in these implementations, it is assigned a non-
function value?
f = 23;
The misconception might have occurred in the author(s) because up to
including ECMAScript Edition 3 the creation of Function instances from
/FunctionDeclaration/s was described as part of a process labeled “Variable
Instantiation” (because it involves evaluating /VariableDeclaration/s as
well; [ES3], §10.1.3)
> dynamic script creation (via eval),
This statement is at least debatable. eval() does not help creating a
script dynamically. A value of the String type it is passed as argument is
interpreted as an ECMAScript /Program/ ([ES], §15.1.2.1), taking into
account the (Mozilla) JavaScript extensions of the ECMAScript grammar [MDN].
> object introspection (via for ... in),
True, but insufficient; probably simplifying or historic, potentially
misleading. A for-in statement can only show the *enumerable* properties
that an object has and inherits. ([ES], §12.6.4)
Methods introduced with ECMAScript Edition 5, namely
Object.getOwnPropertyNames() ([ES], §15.2.3.4) – which considers non-
enumerable properties, but ignores inherited ones –,
Object.getOwnPropertyDescriptor() ([ES], §15.2.3.3) – which gives
information about property attributes –, and __proto__ and its ES3+
counterpart Object.getPrototypeOf() ([ES], §15.2.3.2) – which allows to
inspect the inherited ones –, allow for much deeper introspection. (Current
JavaScript versions are implementations of ECMAScript Ed. 5 and the Ed. 6
Draft. [MDN])
> and source code recovery (JavaScript programs can decompile function
> bodies back into their source text)«
Wishful thinking, potentially misleading. That there is the *possibility*
of this is a consequence of the fact that Function instances (objects
created with a /FunctionDeclaration/, /FunctionExpression/ or the Function
constructor) inherit a “toString” method from their prototype, the object
initially referred to by τhe expression “Function.prototype”. That
toString() method is specified in [ES] to return a string value that matches
the /FunctionDeclaration/ production.
However, no guarantee is given anywhere in the original JavaScript
documentation (eventually at [DevEdge]) or in the ECMAScript Language
Specification that it will be the decompiled source code. In fact, the
Specification explicitly says that the value is implementation-dependent
([ES], §15.3.4.2). That implementation-dependence can be observed when
comparing the return values of various “JavaScript”s (ES implementations
that have “JavaScript” in their name), showing that they are indeed
different implementations of that Specification. For example, some
“JavaScript”s return a string value containing the original comments while
others do not. We have discussed this here before.
Finally, the term “function” appears to be underdefined in that statement.
The above does not apply to all functions in the sense of callable objects,
but only to *user-defined* functions as defined in the first paragraph of
this section. As an example, the built-in object referred to by the initial
value of “Object.prototype.toString” is a Function instance but it
violates/extends the Specification as its toString() method returns
"function toString() {\n [native code]\n}"
which (evaluated) cannot be produced by /FunctionDeclaration/: “[native
code]” is not a valid expression.
> A definitions of the meaning of a term is not »true« or
> »false«, rather it is »agreed upon« or »not agreed upon«
> within a certain group of parties.
For reasons that should be obvious by now, I cannot agree with the cited
statement as a whole; in fact, I find that I can fully agree (in the sense
that I would sign it) only with the first phrase of its first sentence.
__________
[0] <https://developer.mozilla.org/en-US/>, “Help improve MDN”
[DevEdge]
<http://wayback.archive.org/web/20040929085837/http://devedge.netscape.com/central/javascript/>
[DOMCore] <http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html>
[ES] <http://ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf>
[ES3] <http://ecma-international.org/publications/files/ECMA-ST-ARCH/ECMA-262,%203rd%20edition,%20December%201999.pdf>
[MDN] <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference>
--
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
Re: "i = i|0" Ike Naar <ike@iceland.freeshell.org> - 2014-06-11 21:09 +0000
Re: "i = i|0" James Kuyper <jameskuyper@verizon.net> - 2014-06-11 17:37 -0400
Re: "i = i|0" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-12 00:56 +0200
Re: "i = i|0" raltbos@xs4all.nl (Richard Bos) - 2014-06-12 11:41 +0000
Re: "i = i|0" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-12 14:28 +0200
Re: "i = i|0" James Kuyper <jameskuyper@verizon.net> - 2014-06-12 08:19 -0400
Re: "i = i|0" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-12 14:45 +0200
Re: "i = i|0" James Kuyper <jameskuyper@verizon.net> - 2014-06-12 09:25 -0400
Re: "i = i|0" raltbos@xs4all.nl (Richard Bos) - 2014-06-12 14:50 +0000
Re: "i = i|0" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-12 16:55 +0200
Re: "i = i|0" Keith Thompson <kst-u@mib.org> - 2014-06-12 11:28 -0700
Re: "i = i|0" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-12 20:46 +0200
Re: "i = i|0" Christoph Michael Becker <cmbecker69@arcor.de> - 2014-06-12 20:58 +0200
Re: "i = i|0" Kaz Kylheku <kaz@kylheku.com> - 2014-06-12 19:20 +0000
Re: "i = i|0" Christoph Michael Becker <cmbecker69@arcor.de> - 2014-06-12 22:13 +0200
Re: "i = i|0" Kaz Kylheku <kaz@kylheku.com> - 2014-06-12 21:15 +0000
Re: "i = i|0" Christoph Michael Becker <cmbecker69@arcor.de> - 2014-06-12 23:59 +0200
Re: "i = i|0" Christoph Michael Becker <cmbecker69@arcor.de> - 2014-06-13 01:10 +0200
Re: "i = i|0" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-13 01:52 +0200
ECMAScript standards (was: "i = i|0") Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-15 12:53 +0200
Re: "i = i|0" Stephen Sprunk <stephen@sprunk.org> - 2014-06-12 17:11 -0500
Re: "i = i|0" Denis McMahon <denismfmcmahon@gmail.com> - 2014-06-12 22:40 +0000
Re: "i = i|0" glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-06-12 22:44 +0000
Re: "i = i|0" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-13 01:16 +0200
Re: "i = i|0" raltbos@xs4all.nl (Richard Bos) - 2014-06-16 12:55 +0000
Re: "i = i|0" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-16 22:44 +0200
Re: "i = i|0" Thomas Richter <thor@math.tu-berlin.de> - 2014-06-13 19:16 +0200
Re: "i = i|0" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-13 19:21 +0200
Re: "i = i|0" Tim Streater <timstreater@greenbee.net> - 2014-06-13 18:24 +0100
Re: "i = i|0" Kaz Kylheku <kaz@kylheku.com> - 2014-06-13 21:25 +0000
Re: "i = i|0" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-12 17:13 +0200
Re: "i = i|0" raltbos@xs4all.nl (Richard Bos) - 2014-06-12 15:20 +0000
Re: "i = i|0" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-12 17:32 +0200
Re: "i = i|0" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-17 12:30 +0200
Re: "i = i|0" James Kuyper <jameskuyper@verizon.net> - 2014-06-12 12:17 -0400
Re: "i = i|0" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-12 20:01 +0200
Re: "i = i|0" James Kuyper <jameskuyper@verizon.net> - 2014-06-12 16:13 -0400
Re: "i = i|0" glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-06-12 20:44 +0000
Re: "i = i|0" Kaz Kylheku <kaz@kylheku.com> - 2014-06-12 20:59 +0000
Re: "i = i|0" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-13 01:22 +0200
Re: "i = i|0" Martin Shobe <martin.shobe@yahoo.com> - 2014-06-12 19:48 -0500
Re: "i = i|0" "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2014-06-12 18:32 -0700
Re: "i = i|0" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-13 12:12 +0200
Re: "i = i|0" John Harris <niam@jghnorth.org.uk.invalid> - 2014-06-13 10:16 +0100
Re: "i = i|0" Tim Streater <timstreater@greenbee.net> - 2014-06-13 11:44 +0100
Re: "i = i|0" "BartC" <bc@freeuk.com> - 2014-06-12 15:06 +0100
Re: "i = i|0" Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-06-12 16:54 +0200
csiph-web