实现带有状态接口的 Typescript 函数
Implementing a Typescript Function-With-State-Interface
给出下面的界面。我如何实际实施它?我很难想出函数调用的正确语法。
export interface IFoo<T> {
(newValue?: T): T;
state: any;
}
例如:
var tmp: any = function(newValue = 'Hello!') {
return newValue;
}
tmp.state = 123;
var foo: IFoo<string> = tmp;
console.log(foo.state);
console.log(foo());
给出下面的界面。我如何实际实施它?我很难想出函数调用的正确语法。
export interface IFoo<T> {
(newValue?: T): T;
state: any;
}
例如:
var tmp: any = function(newValue = 'Hello!') {
return newValue;
}
tmp.state = 123;
var foo: IFoo<string> = tmp;
console.log(foo.state);
console.log(foo());