最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Transcompile jQuery to JavaScript - Stack Overflow

programmeradmin0浏览0评论

I know all internal jQuery functions are written in JavaScript, so it should technically be possible to just evaluate jQuery to 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?

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.

I know all internal jQuery functions are written in JavaScript, so it should technically be possible to just evaluate jQuery to 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?

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.

Share Improve this question edited Jan 25, 2012 at 22:37 Tim van Dalen asked Jan 25, 2012 at 22:08 Tim van DalenTim van Dalen 1,4713 gold badges22 silver badges41 bronze badges 8
  • 3 jQuery is JavaScript. There is no border to cross here. I would think it is impossible to extract "just the necessary parts" from it, you should focus on getting jQuery into your environment, if you need it. – Tomalak Commented Jan 25, 2012 at 22:09
  • 2 I know jQuery is built up from JavaScript. I'm not saying I would like to extract some parts of jQuery. Say I have $(".classname"). This would be roughly equivalent to document.getElementsByClassName("classname"). I was just asking if there is a tool that does this kind of stuff programmatically. – Tim van Dalen Commented Jan 25, 2012 at 22:31
  • No, there isn't. Everything in jQuery depends on everything in jQuery. While there might be easy substitutes for easy cases, even with your simple example there is a problem: not every browser supports getElementsByClassName(), but every browser jQuery runs on supports $(".classname"). – Tomalak Commented Jan 25, 2012 at 22:38
  • 1 Okay, I was just wondering if there was a tool that helped with replacing jQuery statements with the actual underlying code. I take it there is no such tool. – Tim van Dalen Commented Jan 25, 2012 at 22:46
  • 3 This is a reasonable question. I was also looking for a transcompiler hoping to map jQuery to native inline JavaScript for various reasons. – Pete Alvin Commented Mar 17, 2014 at 11:53
 |  Show 3 more comments

1 Answer 1

Reset to default 16

Google's Closure Compiler's advanced optimization compresses your code to only include parts that are necessary, so the parts of jQuery that aren't used are stripped away.

发布评论

评论列表(0)

  1. 暂无评论