On 17-08-19 01:34 PM, T.J. Crowder wrote:

An ECMAScript *language type* corresponds to values that are directly
manipulated by an ECMAScript programmer using the ECMAScript language. The
ECMAScript language types are Undefined, Null, Boolean, String, Symbol,
Number, and Object. An *ECMAScript language value* is a value that is
characterized by an ECMAScript language type.

...and said "So objects are values."

Is he/she right?

Within the context of the ECMAScript spec, yes.

I've used the term "value" in explanations of variables, properties, and
function arguments and in particular when explaining why `b = a` copies an
object reference, not an object, from `a` to `b`. (Saying the *object
reference* is the value.) It's been an invaluable aid to helping people
"get" object references.

(Note that the spec has a Reference type, but Reference values are not used in this way.)

I'd be very sorry to hear that I was misusing a term of art. But I'd rather
know. :-)

I wouldn't say you're misusing a term of art, you're just using different terminology from the spec.

If I'm misusing "value," what should I use instead for that thing that
actually gets stored in memory?  How to explain the `b = a` thing with
object references to beginners?

You should just keep using whatever works. If necessary, you can say that the terminology you're using doesn't quite match the spec's terminology, but that's unlikely to be a problem.


Still, it's an interesting question of how to explain "the `b = a` thing" in spec terms. It depends on the context, but typically the interesting part will boil down to an invocation of SetMutableBinding, and then bottom out with an action like:
    Set the bound value for 'b' (in some environment record)
    to the value that is currently bound to 'a'.
or
    Set the [[Value]] attribute of the property named 'b' (of some object)
    to the value that is currently bound to 'a'.
(I think I got that right.)
The point is that, if `a` is currently bound to an object, then the value being bound to 'b' is (in spec terms) that object, not a reference to it or a pointer to it or the address of it -- those terms don't exist in the spec.

To understand the spec's model (or make sense of its wording), it may help to imagine all the various values just floating around in value space. When an environment record binds 'b' to a value X (object or number or string, whatever), it doesn't stuff that value into a box somewhere, it merely creates an association between 'b' and X. (You could say that assignment always shares values, never copies values. But it's only with objects that the distinction is observable.)

-Michael
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to