I know there are lots of tools on the net that can make our lives easier, for us, developers, including some that are quite powerful.
I ask if you know a tool to translate old javascript into jQuery?
A tool that can help make this stuff ? Because I have to translate thousands of lines of code in jQuery, and I think I have about 15 years... :)
Thanks !
I know there are lots of tools on the net that can make our lives easier, for us, developers, including some that are quite powerful.
I ask if you know a tool to translate old javascript into jQuery?
A tool that can help make this stuff ? Because I have to translate thousands of lines of code in jQuery, and I think I have about 15 years... :)
Thanks !
Share Improve this question asked Jul 5, 2012 at 9:57 Clément AndraudClément Andraud 9,26927 gold badges86 silver badges160 bronze badges 7- Im not sure I understand what exactly it is you want to do. JQuery is a extension of Javascript, it allows you to do all the same stuff javascript already does, but through a nice api. If the javascript works already why would you be converting to jquery? – Jon Taylor Commented Jul 5, 2012 at 9:59
- @JonTaylor jQuery is Cross Browser Compatible! – Praveen Kumar Purushothaman Commented Jul 5, 2012 at 10:01
- Yes, i want a cross browser javascript. My current code is 10 years old... – Clément Andraud Commented Jul 5, 2012 at 10:02
- @Praveen Kumar So is javascript if its written in the correct way. I'm not seeing your point to be honest. Every single thing you can do in JQuery, you can do in straight Javascript, since JQuery is just a set of functions written in Javascript. – Jon Taylor Commented Jul 5, 2012 at 10:11
- 1 @Praveen Kumar I understand the advantages of using JQuery, but people often assume that using it allows them to do things Javascript does not allow. This is a false assumption. I can create a cross browser website in pure Javascript, yes it takes more work but JQuery is not mandatory to create cross browser website. What he should be doing is figuring out the parts that are not working, from a cross browser point of view and fixing these. – Jon Taylor Commented Jul 5, 2012 at 10:20
2 Answers
Reset to default 6No, such a tool doesn't exist. If it existed the code created by it wouldn't be something anyone wanted to work with.
The best way to start using jQuery is simply using jQuery for new stuff and if there's time slowly migrating old stuff manually - preferably stuff that's broken or needs modifications anyway.
The question doesn't make sense. jQuery is not a language that you can translate into. jQuery is a library that you can use in your Javascript code if you want. There is nothing jQuery can do that can't be done without it.
What you probably want is a tool to help you refactor your Javascript code, replacing specific patterns with equivalent jQuery methods. The problem is that this would produce a mess.
E.g. the jQuery equivalent to:
var x = document.getElementById('foo');
is:
var x = $('#foo');
but now x is a jQuery object, not a DOM object, so the code that uses it will break.
You could do:
var x = $('#foo')[0];
which would give you a DOM object, but then you are wasting jQuery.
One solution is to replace the code with:
var $x = $('#foo');
var x = $x[0];
Then stick to the convention that $var
is the jQuery wrapped version of var
. As refactoring progresses, you can use a tool that tells you 'x' is unused (like jsLint) to know that it's safe to remove it.
Various IDEs have tools to refactor Javascript a bit. See this question for some: How do you refactor JavaScript, HTML, CSS, etc?