Comments (9)
How would one disallow extension? Everything that ES provides can be a superclass, afaik.
from proposal-record-tuple.
Why allow
class A extends Tuple {
at all?
One argument is consistency with other recently added types, extends BigInt
is allowed in the same way. Hard to say when to start a new pattern vs follow existing conventions.
from proposal-record-tuple.
@nicolo-ribaudo Yes, that's what I mean.
https://tc39.es/proposal-record-tuple/#sec-tuple.prototype.concat
See the loop in step 5.c.v.
If an expected numeric index does not exist, nothing is appended to the tuple.
I believe it should be appending an undefined
value for that case.
from proposal-record-tuple.
Regarding extension, new class extends Symbol { constructor(desc) { return arguments.length > 0 ? Object(Symbol(desc)) : Object(Symbol()); } }
works, and i'd expect a similar approach to work for Record and Tuple for consistency.
from proposal-record-tuple.
@ljharb It seems to me that there are other globals that cause an exception if you try to use them in an extends clause.
For example:
C = class extends parseFloat {};
Generates this exception in Chrome:
VM287:1 Uncaught TypeError: Class extends value function parseFloat() { [native code] } is not a constructor or null
at <anonymous>:1:19
I haven't yet tried to find which part of the spec specifies this behavior, but perhaps you already know?
from proposal-record-tuple.
Ah, yes - functions without a .prototype. However, that wouldn’t make sense when there can be instances of both.
from proposal-record-tuple.
I don't see a strong reason to push back on the extension bullet point.
It would be nice to simply refuse to accept Record
or Tuple
in the extends
slot, but I don't think its crucial.
The exception throw by calling super()
is likely sufficient discouragement.
What about the concat()
behavior bullet point, though?
Was this deviation from Array.prototype.concat()
intentional?
Did I miss documentation for why this choice was made?
from proposal-record-tuple.
Did you mean that #[].concat({ 0: "a", 2: "b", length: 3 })
currently produces #["a", "b"]
instead of #["a", undefined, "b"]
? If yes, it's a spec bug.
from proposal-record-tuple.
Edit: I just learned that "The … constructor … is not intended to be used with the new operator or to be subclassed." For others who may not understand the reason why.
I do agree with @ljharb, sometimes consistency trumps reason. This should work, as it does in the playground:
new class extends Record { constructor(obj = {}) { return Object(Record(obj)); } }
from proposal-record-tuple.
Related Issues (20)
- Record keys are deduplicated, but should duplicates generate a thrown error? HOT 5
- Forbid hosts creating an impossible records/tuples
- Can we agree on a list of design goals for the README? HOT 2
- Upgradeable ArrayBuffers HOT 5
- add support for tuples to {Async,}Iterator.prototype.flatMap and {Async,}Iterator.from
- `Record` name conflict with Typescript HOT 1
- Why mixing immutability and tuples ? HOT 5
- `let` binding record and tuple should be writable HOT 6
- Some syntactic sugar: no need to insert # before every nested structure HOT 4
- Is this planned for ES14? HOT 6
- What about sets? HOT 14
- Record and Tuple creation should be recursive. HOT 5
- Can I use? HOT 9
- Is empty tuple / record falsy? HOT 8
- Syntax problems with VSCode HOT 2
- Does `.with()` accept array as first argument? HOT 1
- Map/Set’s SameValueZero key/value mapping HOT 2
- Looking to confirm: CanBeHeldWeakly remains false even if rec/tup includes unforgeable symbols? HOT 2
- Tuple.fromAsync?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from proposal-record-tuple.