Reputation: 482
I have a app in nodejs, using VS Code, compiling with gulp-typescript-compiler, target ECS5, commonjs. Creating a basic class with error 'Error: Unexpected token; 'constructor, function, accessor or variable' expected on src/app/Test.ts line 7.'
Following code:
class Test {
public name:string;
testing () {
console.log('tested...');
}
this.testing();
}
//gulp task error compile
//Error: Unexpected token; 'constructor, function, accessor or variable' expected on src/app/Test.ts line 7.
Upvotes: 0
Views: 1180
Reputation: 239250
You can't invoke a method inside a class declaration. The line this.testing()
cannot go there.
It's not clear why you would want to invoke the method there, or when you think that method would be invoked. Perhaps you're looking for the constructor? As it stands, that line makes no sense in that location.
Upvotes: 3