question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Allow the omission of the superclass

See original GitHub issue

Currently the syntax is:

class MyClass extends mix(MySuperClass).with(MyMixin1, MyMixin2) {
}

How about the following?

class MyClass extends mixins(MyMixin1, MyMixin2, MySuperClass) {
}

Details:

  • This better reflects the order of the inheritance chain
  • The last parameter should be optional (you may want to create classes that only assemble mixins and have no superclass)
  • The function could do a simple typecheck by enforcing that the mixins must not have a property prototype, while the superclass (the optional last parameter) must have this property.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:3
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
psayre23commented, Dec 24, 2015

If this syntax is acceptable:

class MyClass extends mix().with(MyMixin1, MyMixin2) {

…then you could throw this check in for mix constructor:

if(typeof superclass !== "object" || superclass === null) {
    superclass = Object;
}

That would default to having Object as a superclass…which everything is, so that’s technically true.

1reaction
trusktrcommented, Jul 14, 2016

I was just thinking about this, as I thought “what if I don’t have a super class, and just want to extend from some mixins?”.

if (typeof superclass !== "object" || superclass === null) {
    superclass = Object;
}

That would default to having Object as a superclass…which everything is, so that’s technically true.

Object can be replaced at runtime, whereas class {} always extends from the internal [[Object]], so possibly it’s better to use an empty class anyway.

if (typeof superclass !== "object" || superclass === null) {
    superclass = class {};
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Always allow code before super call when it does not use "this"
The first statement in the body of a constructor must be a super call if both of the following are true: The containing...
Read more >
PHP superclass calling subclass methods without knowing ...
PHP is very dynamic language and it allows you to use polymorphism without inheritance. In this case, it simply looks ...
Read more >
Abstract Classes
We can treat an abstract class as a superclass and extend it; its subclasses can override some or all of its inherited abstract...
Read more >
Design and document for inheritance—or else prohibit it ...
There are a few more restrictions that a class must obey to allow inheritance. Constructors must not invoke overridable methods, directly or ...
Read more >
database T/F Flashcards - Quizlet
Superclass may not contain overlapping subclasses ... during the conceptual design is the omission of certain attributes, entities, or relationships.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found