Giter VIP home page Giter VIP logo

Comments (7)

wolframkriesing avatar wolframkriesing commented on July 20, 2024

if i read the spec (I am not sure if I read the wrong part) it looks like its is possible
https://tc39.es/ecma262/#sec-runtime-semantics-classdefinitionevaluation
in 5e it says "If superclass is null, then" and MDN also still says "The .prototype of the extension must be an Object or null."

Do I read those wrong?

from katas.

wolframkriesing avatar wolframkriesing commented on July 20, 2024

though i dont get it work anywhere neither, here chrome (canary) console

> class A extends null {}
undefined
> new A
VM79:1 Uncaught TypeError: Super constructor null of A is not a constructor
    at new A (<anonymous>:1:1)
    at <anonymous>:1:1

and node repl

> class A extends null {}
undefined
> new A
Uncaught TypeError: Super constructor null of A is not a constructor
    at new A (repl:1:1)

from katas.

wolframkriesing avatar wolframkriesing commented on July 20, 2024

yeah the only useful thing to learn is what you described. But not really of any practical value, is it?

So I would rather change this test to verify that a parent must be callable with super() and since null has no super it throws. Does that makes sense?

    it('a class extending `null` can not be instantiated, since calling `super()` on null fails', () => {
      class NullClass extends null {}
      assert.throws(() => new NullClass);
    });

like this

from katas.

shinenelson avatar shinenelson commented on July 20, 2024

I'm not really sure. Wouldn't that be kind of misleading new developers to assume that a class may extend null?

We should either remove the whole test or explain the rationale behind the use-case. And also somehow probably document somewhere ( in the test itself ) that this is a gray-area test.

Do I read those wrong?

No, what you're reading is correct. The spec was first made to extend null, but then apparently many bad things happened and they reverted it ( see links in issue description )

I found this question on StackOverflow that questions this use-case altogether. The question has different errors of this use-case not working

PS : the issue title is probably misleading, what I meant was that it was broken by ECMAScript and that it wasn't our fault.

from katas.

wolframkriesing avatar wolframkriesing commented on July 20, 2024

i agree, either 1) remove the test or 2) make it more explicit, maybe like that:

it('`extends null` is not supported', () => {
      class NullClass extends null {}
      assert.throws(() => new NullClass);
});

just to mention the edge case and its solution.
What do you think?

from katas.

shinenelson avatar shinenelson commented on July 20, 2024

actually, it is supported by the spec, it's just not working as intended. So, maybe, the test should be extends null is broken or something along those lines maybe?

from katas.

shinenelson avatar shinenelson commented on July 20, 2024

the MDN revision used the term 'not allowed', so, I guess 'not supported' is close enough. I'd favor 'not allowed' though.

from katas.

Related Issues (19)

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.