Giter Club home page Giter Club logo

Comments (9)

ljharb avatar ljharb commented on June 1, 2024 1

How would one disallow extension? Everything that ES provides can be a superclass, afaik.

from proposal-record-tuple.

acutmore avatar acutmore commented on June 1, 2024 1

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.

brad4d avatar brad4d commented on June 1, 2024 1

@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.

ljharb avatar ljharb commented on June 1, 2024 1

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.

brad4d avatar brad4d commented on June 1, 2024

@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.

ljharb avatar ljharb commented on June 1, 2024

Ah, yes - functions without a .prototype. However, that wouldn’t make sense when there can be instances of both.

from proposal-record-tuple.

brad4d avatar brad4d commented on June 1, 2024

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.

nicolo-ribaudo avatar nicolo-ribaudo commented on June 1, 2024

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.

joakim avatar joakim commented on June 1, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.