We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
super()
this
class定义始终是 严格模式代码。
// 有意思,直接空语句也行 class ClassTest{ ; test; }
« "*default*" »
class Test{ constructor() { // ... } }
class Test{ constructor() { // ... } handle() { // ... } }
class Cla{} typeof Cla // 'function'
伴有参数 classBinding 和 className。
constructor(...args) { super(...args); }
constructor() { }
注意:ClassDeclaration : class ClassTail 仅作为 ExportDeclaration 的一部分出现并且从不直接求值。
// 静态方法 // static 关键字用来定义一个类的一个静态方法。 // 调用静态方法不需要实例化该类,但不能通过一个类实例调用静态方法。 class Point { constructor(x, y) { this.x = x; this.y = y; } static distance(a, b) { const dx = a.x - b.x; const dy = a.y - b.y; return Math.hypot(dx, dy); } } const p1 = new Point(5, 5); const p2 = new Point(10, 10); console.log(Point.distance(p1, p2)); console.log(p1.distance); // undefined // 公有字段 与 私有字段 class Rectangle { height = 0; // 公有字段 #width; // 私有字段 constructor(height, width) { this.height = height; this.#width = width; } } // 来自高级前端面试,我做错了 class Chameleon{ static colorChange(newColor) { this.newColor = newColor; } constructor({newColor = 'green'}) { this.newColor = newColor; } } const freddie = new Chameleon({newColor: 'purple'}) freddie.colorChange('orange') // 选D A. orange B. purple C. green D. TypeError // 同理,下面也是报错 class test extends Chameleon{ constructor() { super({newColor: 'purple'}) super.colorChange('red') } } new test // TypeError
The text was updated successfully, but these errors were encountered:
No branches or pull requests
类定义(class)
super()
只能在构造函数中使用,并且必须在使用this
关键字前调用BoundNames
ClassDeclaration : class BindingIdentifier ClassTail
ClassDeclaration : class ClassTail
« "*default*" »
ConstructorMethod (构造器方法)
ClassElementList : ClassElement
ClassElementList : ClassElementList ClassElement
IsFunctionDefinition (是不是函数)
NonConstructorMethodDefinitions (非构造器方法定义)
ClassElementList : ClassElement
ClassElementList : ClassElementList ClassElement
ClassDefinitionEvaluation
伴有参数 classBinding 和 className。
ClassTail : ClassHeritageopt { ClassBodyopt }
Yield, Await] 一起使用Yield, Await] 一起使用BindingClassDeclarationEvaluation
ClassDeclaration : class BindingIdentifier ClassTail
ClassDeclaration : class ClassTail
求值
ClassDeclaration : class BindingIdentifier ClassTail
ClassExpression : class BindingIdentifieropt ClassTail
The text was updated successfully, but these errors were encountered: