Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

继承EventEmitter的子类中,this未定义?

$
0
0

“use strict”; var EventEmitter = require(‘events’); class Rectangle extends EventEmitter { constructor (width, height) { this._width = width this._height = height } set width (width) { this._width = width } get width () { return this._width } set height (height) { this._height = height } get height () { return this._height } get area () { return this._width * this._height } } var r = new Rectangle(50, 20); 运行上面代码的时候,已知提示this未定义,把extends EventEmitter注释掉之后,就正常了,这是为何?


Viewing all articles
Browse latest Browse all 14821

Trending Articles