开发者

Prepare script to compile in JavaScript compiler (Google Closure)

I have code written in many places. I want to refactor the code to be able to use JavaScript compiler for performance and syntax check reasons. What is the recommendation to prepare the code for compiling?

  • I have JavaScript code written with EJS to render some server-side data in JavaScript:

Code:

<% if(product.type){ %>
        $('#someid').html('<%= product.type %>');   //javascript
<% } %>
  • I think the compiler will change my variables name (I know it can be set not to change which variable, but I have so many of them used across the pages, scripts, or widgets/subpages; something like global var), in that case it'll surely collapse my code.

I've heard that writing in closure style 开发者_如何转开发helps variable collision between each script files. Do I have to rewrite all code using that pattern? Do I have to construct the code from scatch? I'm asking for the way to prepare the code to be compiled, any suggestion?


The compiler does not change global and property names. It just renames the local variables and removes the whitespace.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜