【发布时间】:2016-10-28 22:11:19
【问题描述】:
需要有关我正在尝试学习的以下代码的建议。我正在使用 typescript 1.8.10 编译器和 EM5:
module myAwersome.module{
'use strict';
export interface INavigateService {
links: string[],
getLinks():void
}
class Test implements INavigateService {
links:string[] = [];
getLinks():void {
links.push("hello world"); //ERROR unable to find name links
}
}
【问题讨论】:
-
使用this.links解决
-
当 Test 类被转译为 JavaScript 时,'links' 属性在函数构造函数中使用 this.links = []; 进行初始化;
标签: function class variables typescript interface