将 jQuery 转换为 JavaScript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9011095/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Transcompile jQuery to JavaScript
提问by Tim van Dalen
I know all internal jQuery functions are written in JavaScript, so it should technically be possible to just evaluate jQuery to JavaScript.
我知道所有内部 jQuery 函数都是用 JavaScript 编写的,因此从技术上讲,只将 jQuery 评估为 JavaScript 应该是可能的。
I have a snippet of JavaScript that uses jQuery that I need to use in an environment where jQuery isn't available. I know I could translate it by hand, but it is quite a lot of code. Is there a tool out that that does this?
我有一段使用 jQuery 的 JavaScript 片段,我需要在 jQuery 不可用的环境中使用它。我知道我可以手动翻译它,但它是相当多的代码。有没有工具可以做到这一点?
Just to make it clear: with a lot of effort I could probably get jQuery in the environment but I would like to have a solution that is a bit more resource friendly. If there is no tool like this I'll just try to translate the code by hand, I was just wondering whether there was such a tool.
澄清一下:通过很多努力,我可能会在环境中使用 jQuery,但我想要一个对资源更友好的解决方案。如果没有这样的工具,我就试试手工翻译代码,我只是想知道是否有这样的工具。
回答by Casey Chu
Google's Closure Compiler's advanced optimization compresses your code to only include parts that are necessary, so the parts of jQuery that aren'tused are stripped away.
Google 的Closure Compiler的高级优化将您的代码压缩为仅包含必要的部分,因此 jQuery中未使用的部分将被剥离。