-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
Labels
CanonicalThis issue contains a lengthy and complete description of a particular problem, solution, or designThis issue contains a lengthy and complete description of a particular problem, solution, or designQuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in codeWon't FixThe severity and priority of this issue do not warrant the time or complexity needed to fix itThe severity and priority of this issue do not warrant the time or complexity needed to fix it
Description
The following code:
var i = 0, j = 0;
class Base {
get instanceAccessor() { return ++i; }
static get staticAccessor() { return ++j; }
toString = () => 'instance: ' + this.instanceAccessor + ' static: ' + Base.staticAccessor;
}
class Derived extends Base {
toString = () => 'instance: ' + this.instanceAccessor + ' static: ' + Derived.staticAccessor;
}
console.log('Base:\n%s\n%s\n%s', new Base(), new Base(), new Base());
console.log('Derived:\n%s\n%s\n%s', new Derived(), new Derived(), new Derived());
generates the following output (with the v1.3 compiler):
Base:
instance: 1 static: 2
instance: 2 static: 3
instance: 3 static: 4
Derived:
instance: 4 static: 1
instance: 5 static: 1
instance: 6 static: 1
Clearly Derived.staticAccessor
is no longer an accessor, but a 'snapshot' of the value of Base.staticAccessor
when the Derived
constructor function called __extends
.
Just wondering if this is the expected/correct behaviour?
PS. I haven't run into this problem 'in the wild' as I rarely use classes or accessors, but merely came across a rant/blog post about another compile-to-JS language doing something similar, and was curious how TypeScript handled it.
yGuy and jonygli
Metadata
Metadata
Assignees
Labels
CanonicalThis issue contains a lengthy and complete description of a particular problem, solution, or designThis issue contains a lengthy and complete description of a particular problem, solution, or designQuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in codeWon't FixThe severity and priority of this issue do not warrant the time or complexity needed to fix itThe severity and priority of this issue do not warrant the time or complexity needed to fix it