It's in Firefox, and it'll be in the next version of Chrome. Safari is still working on it, but in the meantime there's a couple of polyfills available.
These immutable data types are stored by value, meaning that a variable that represents the number value 3 effectively “contains” — and thus behaves as — the number value 3.
That's an interesting take. JavaScript inherits a lot from Smalltalk via Self. In both of these languages, 3 is just another object, there's no special semantics for them. At the abstract machine level, 3 is always stored by reference. In Smalltalk it's an instance of SmallInt, in JavaScript I think it's an object whose prototype is Number or something. There are no methods that mutate the value of small integers and so as an optimisation, they are stored in the pointer, but that's just the implementation pretending that it's allocated all possible SmallInt values as one-byte singletons in half of the address space. In classic Smalltalk implementations, the low bit of a pointer is a discriminator telling you whether this object is a small integer or something else. Half of the address space (which is usually bigger than total memory) is available for storing objects, the other half is used for storing small integers. But that's purely an optimisation. At the abstract-machine level, SmallInt instances are just instances of objects and they happen to be immutable. Some other classes also have immutable-after-creation instances. JavaScript VMs often employ NaN boxing to store either a double or a pointer in the same space, with pointers encoded in the space in IEEE 64-bit floating-point values for representing not-a-number valuse.
The rest of this bit of the complaint is weird. Yes, dates are mutable. But that's the natural way of building an API in a language that doesn't have a notion of immutability or of value types in the type system.
doctor_eval | 17 hours ago
I like the article and agree with it but
I would like to introduce the author to the marvellous world of truthy.
carlana | 12 hours ago
How many concepts are three? Surely, just one. Therefore, three can be some other non-three thing.
doctor_eval | 4 hours ago
Oh. Yes. That is very good.
wink | 17 hours ago
A coworker of mine quizzed us on some of these in our knowledge sharing session.
My strategy of picking the most cursed interpretation of what it would output had me win by a large margin.
Unfortunately
new Date( "49" )did not give0000-02-18 00:00:00.[OP] greenheart | 6 hours ago
Haha that sounds like a fun session!
LAC-Tech | 5 hours ago
I got very excited because I thought this meant Temporal was finally in our browsers.
Nope, still not there.
It's been decades at this point hasn't it?
Johz | 4 hours ago
It's in Firefox, and it'll be in the next version of Chrome. Safari is still working on it, but in the meantime there's a couple of polyfills available.
david_chisnall | 14 hours ago
That's an interesting take. JavaScript inherits a lot from Smalltalk via Self. In both of these languages, 3 is just another object, there's no special semantics for them. At the abstract machine level, 3 is always stored by reference. In Smalltalk it's an instance of
SmallInt, in JavaScript I think it's an object whose prototype isNumberor something. There are no methods that mutate the value of small integers and so as an optimisation, they are stored in the pointer, but that's just the implementation pretending that it's allocated all possibleSmallIntvalues as one-byte singletons in half of the address space. In classic Smalltalk implementations, the low bit of a pointer is a discriminator telling you whether this object is a small integer or something else. Half of the address space (which is usually bigger than total memory) is available for storing objects, the other half is used for storing small integers. But that's purely an optimisation. At the abstract-machine level,SmallIntinstances are just instances of objects and they happen to be immutable. Some other classes also have immutable-after-creation instances. JavaScript VMs often employ NaN boxing to store either a double or a pointer in the same space, with pointers encoded in the space in IEEE 64-bit floating-point values for representing not-a-number valuse.The rest of this bit of the complaint is weird. Yes, dates are mutable. But that's the natural way of building an API in a language that doesn't have a notion of immutability or of value types in the type system.
Gaelan | 12 hours ago
JavaScript is weird. Primitives are genuinely their own type of thing, distinct from objects:
But there is a Number "class"*:
And method calls on primitive numbers will implicitly create an instance of
Numberif needed. Other primitive types are similar.*yes, yes, prototype thing that quacks like a class
fanf | 8 hours ago
Non-object primitive types with differently-typed object wrappers is something JavaScript copied from Java. Like the Date class…