Reputation: 1131
In the deep internet I encountered structure like class A extends B with C { ... }
, I haven't link right now, it was like macro for class while extending abstract class.
Is this in standard? (I googled, only finding old with
that is removed right now, chrome inline console throws error)
Upvotes: 4
Views: 612
Reputation: 288100
It's not standard. From Annex A.4 - Functions and Classes, the syntax is
ClassDeclaration[Yield, Default] :
class BindingIdentifier[?Yield] ClassTail[?Yield]
[+Default] class ClassTail[?Yield]
ClassExpression[Yield] :
class BindingIdentifier[?Yield]opt ClassTail[?Yield]
ClassTail[Yield] :
ClassHeritage[?Yield]opt { ClassBody[?Yield]opt }
ClassHeritage[Yield] :
extends LeftHandSideExpression[?Yield]
So the ClassTail is the part which includes both the optional extends something
and the class body. And that something
must be a LeftHandSideExpression, without any with
in there.
Upvotes: 2
Reputation: 4310
No this is not a part of the ECMAScript 6 Classes standard. See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes
The with
keyword is used in some programming languages to signify multiple inheritance.
Scala for example has traits which classes can extend from with the with
keyword
trait Drawable {
def draw() { }
}
trait Cowboy extends Drawable {
override def draw() { println("Bang!") }
}
trait Artist extends Drawable {
override def draw() { println("A pretty painting") }
}
class CowboyArtist extends Cowboy with Artist
Upvotes: 2