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 !
No, 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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With