[英]coffee -> javascript -> typescript
I'm converting coffeescripts to typescript and have trouble with one simple delay type function. 我正在将coffeescripts转换为typescript,并且遇到一个简单的延迟类型函数的麻烦。
The coffeescript: 咖啡脚本:
ise.utils.delay = (->
timer = 0
(callback, ms) ->
clearTimeout timer
timer = setTimeout(callback, ms)
)()
The produced javascript: 产生的javascript:
ise.utils.delay = (function() {
var timer;
timer = 0;
return function(callback, ms) {
clearTimeout(timer);
return timer = setTimeout(callback, ms);
};
})();
When I enter the produced js into a typescript file I get a compile error. 将生成的js输入到打字稿文件中时,出现编译错误。
I can't figure out what is wrong. 我不知道怎么了。
If the above code is all the code you have, then you are missing var ise = { utils: { delay: {}}}
如果上面的代码是您拥有的所有代码,那么您将丢失var ise = { utils: { delay: {}}}
I think what you are actually looking for is modules in TypeScript like below 我认为您实际上正在寻找的是TypeScript中的模块,如下所示
module ise.utils {
var timer = 0;
export function delay(callback, ms) {
clearTimeout(timer);
return timer = setTimeout(callback, ms)
};
}
I ended up using this: 我最终使用了这个:
module ise { export module utils { var timer = 0; export function delay(callback, ms) { clearTimeout(timer); return timer = setTimeout(callback, ms) };
... Thanks... ... 谢谢...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.