Objects contain references to their fields, but they are always passed by value. This is probably the distinction you're looking for.
On Sat, Aug 19, 2017, 16:32 Alex Kodat <[email protected]> wrote: > While it does appear the that ECMAScript spec calls objects values, that > seems pretty unintuitive to me. My intuition is that values are immutable > (functions can and frequently do have properties added to them). The > typical > distinction seems to me between values and variables. If you set a variable > to an object value how is it that the variable value changes when you > change > another variable? If, on the other hand, you view object values as > references to object then changing one variable's value will never change > another's which seems a nicer view of the world. But that was T.J.'s point, > I think. > > Note that strings are also generally indistinguishable from immutable > objects and are generally passed by reference under the covers but, because > they're immutable, one can safely think of the value being the actual > string > rather than the reference. Numbers can be and sometimes are implemented as > immutable objects too. Like V8 implements 32-bit signed integers as pure > values and larger numbers are boxed (into hidden objects) double values. > > -----Original Message----- > From: es-discuss [mailto:[email protected]] On Behalf Of kdex > Sent: Saturday, August 19, 2017 1:55 PM > To: [email protected] > Subject: Re: Are objects values? > > I never claimed it was. I'm sure the notion of "value" that ECMAScript > wants > to convey is supposed to be something along the lines of "can be bound to > an > identifier". > > The semantics that are then defined over primitive/non-primitive values are > a completely different matter. > > On Saturday, August 19, 2017 8:44:08 PM CEST Naveen Chawla wrote: > > But references are also values. It's not a mutually exclusive thing > > > > On Sat, 19 Aug 2017, 11:32 p.m. kdex <[email protected]> wrote: > > > Yes, objects/functions are values, but they are not *primitive* values. > > > > > > The current draft uses the phrasing "object value" several times. > > > > > > Section 4.3.3 explains that objects are "members of type Object", > > > and a type is, by definition, a set of values. Therefore, objects > > > must be values. > > > > > > On Saturday, August 19, 2017 7:34:45 PM CEST T.J. Crowder wrote: > > > > I recently had an exchange which started out with my "correcting" > > > > someone > > > > who said "Functions are values" by saying "Function *references* > > > > are values. Functions are objects." He/she replied that objects > > > > are also values, and after much back and forth, cited [this part > > > > of the JavaScript > > > > > > > > spec][1]: > > > > > 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? [Wikpedia][2] isn't much help, at least not to > > > > me. I > > > > > > asked > > > > > > > a friend who, unlike me, did get comp sci theory at Uni, and he > > > > said "...you're not wrong, but it's very Humpty Dumpty: When I use > > > > a word, it means just what I choose it to mean -- neither more nor > less." > > > > > > > > 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. > > > > > > > > I'd be very sorry to hear that I was misusing a term of art. But > > > > I'd > > > > > > rather > > > > > > > know. :-) > > > > > > > > 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? > > > > > > > > This is slightly off-topic for the thread, but also not, as I > > > > spend a lot of time explaining things to JavaScript beginners, and > > > > the authors of the text being used to tell me I'm wrong are on > > > > this list. :-) > > > > > > > > Thanks, > > > > > > > > -- T.J. Crowder > > > > > > > [1]: > > > http://www.ecma-international.org/ecma-262/8.0/index.html#sec-ecmasc > > > ript-l > > > an> > > > > guage-types [2]: > > > > https://en.wikipedia.org/wiki/Value_(computer_science) > > > > > > _______________________________________________ > > > es-discuss mailing list > > > [email protected] > > > https://mail.mozilla.org/listinfo/es-discuss > > _______________________________________________ > es-discuss mailing list > [email protected] > https://mail.mozilla.org/listinfo/es-discuss >
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

