[英]typescript/JS module pattern. splitting into multiple files
Please see the code below . 请参见下面的代码 。
module AAA {
export module user {
export var am = {}
}
}
//1.
module AAA {
export module user {
am['x']= 'y';
}
}
//2.
module AAA {
export module user {
user.am['x']= 'y';
}
}
I am trying to split a module into two (or more) files. 我正在尝试将一个模块拆分为两个(或更多)文件。 first (1.) form doesn't work, as the code generated sometimes (couldn't produce in playground) looks like (note the underscore)
第一种(1.)形式无效,因为有时生成的代码(无法在运动场中生成)看起来像(请注意下划线)
var AAA;
(function (AAA) {
(function (_user) {
AAA._user.am['x'] = 'y';
})(AAA.user || (AAA.user = {}));
var user = AAA.user;
})(AAA || (AAA = {}));
but, second (2.) form works fine and I get intellisense for variable am
. 但是,第二(2.)形式可以正常工作,并且我对变量
am
获得了智能感知。 is this a reliable way, if I guarantee the order of files referenced? 如果我保证引用的文件顺序,这是一种可靠的方法吗? or do I need to refer from the root like,
AAA.user.am['x']= 'y';
还是我需要从根目录引用
AAA.user.am['x']= 'y';
or a better way? 还是更好的方法?
Also, in the generated code, there are two variable declaration var AAA;
另外,在生成的代码中,有两个变量声明
var AAA;
. 。 Would this cause any issue.
这会引起任何问题。 If I use a minifier, can it rid of it?
如果我使用缩小器,可以去除它吗?
thanks. 谢谢。
This was a bug in the 1.0RC compiler. 这是1.0RC编译器中的错误。 See this page where you can get a hotfix tsc.js file.
请参阅此页面 ,您可以在其中获取修补程序tsc.js文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.