1
请注意,我已经检出this question,但其答案似乎并不正确。打字稿中的私人功能
如果我想在常规的JavaScript私有方法(该答案的建议是不可能的),我会做这样的事情:
function myThing() { var thingConstructor = function(someParam) { this.publicFn(foo) { return privateFn(foo); } function privateFn(foo) { return 'called private fn with ' + foo; } } } var theThing = new myThing('param'); var result = theThing.publicFn('Hi');//should be 'called private fn with Hi' result = theThing.privateFn; //should error
我试图找出语法是什么在TypeScript中封装私有函数。如果事实证明你不能这么做,那很好,但鉴于那个旧问题中的答案错误地指出你不能在普通的JavaScript中创建私有方法,我不愿意仅仅将这些答案作为权威。