假设我有这样的事情:
interface Scope extends ng.Scope {
getMeSome(id:string):number[];
}
export class AwesomeController {
constructor (public $scope:Scope) {
$scope.getMeSome = id => this.getMeSome(id);
}
getMeSome(id:string){
console.log('Alright... alright... here it is');
}
}
现在你可以看到我在 3 个不同的地方有相同的方法签名。当然,我可以把它剪掉一点,然后在构造函数中执行它:
constructor (public $scope:Scope) {
$scope.getMeSome = id => {
console.log('Alright... alright... here it is');
};
}
但这会像使用类固醇一样打击构造函数的身体(如果您有数十种不同的方法)。所以我想知道为什么我不能做这样的事情:
export class AwesomeController {
constructor (public $scope:Scope) { }
$scope.getMeSome(id:string) { // Can't extend $scope here, although I can do that in the constructor
console.log('Alright... alright... here it is');
}
}
为什么这不起作用?有什么让它更性感的建议吗?