Becoming a better JavaScript developer
One of the most important aspects in the life of a coder is the constant strive to learn, learn and learn some more. The industry is evolving and you have to keep up or risk being left behind. This is especially true in the world of JavaScript, which was considered more suitable for rookies and now has evolved to a full fledged
programming language, with a large ecosystem of libraries and frameworks.
Therefore, I am going to present three practices that will help your code evolve as well.
Start using a script loader and better organize your code
By using a script loader you can get rid of all those pesky script tags from the bottom of your <body> or even worse, your <head>. It also provides an easy way to load your scripts asynchronously and handle dependencies, without worrying about the order in which you should declare them.
Another plus for using a script loader is that it helps you write modular and reusable code, by creating and exporting modules.
My script loader of choice is RequireJS, with a well-documented api. Props to its creator, James Burke.
Use a custom jQuery build
What is the first script that you include in a newly created project? Probably your answer is jQuery. I get it, jQuery was the library for the millennium, bringing all the different browser implementations under one nice façade. But nowadays, it became much more than just a simple utility for traversing the DOM, possibly adding unwanted code to your project.
For example, as it's stated on jQuery's github page, there's no need to include all the DOM manipulation functions if you only want to make a jsonp request, using $.ajax.
There's a full list of excludable modules on that page, so feel free to take a look.
Another mention that I want to make on this topic is James Padolsey's jQuery source viewer, an excellent tool for visualising the way in which methods are implemented in jQuery.
Embrace weak typing and learn how to dodge JavaScript's problems
Maybe you miss working in a strongly typed language, or maybe you like being sure that 1 isn't equal to true, or you have no idea why 1/0 in base 19 is equal to 18. But if you want to succeed as a JavaScript programmer, learning when and why "strange" things happen is essential. Considering the multitude of posts on the web regarding this subject, I'm not going to reiterate over those nuisances here, but I'll just leave this useful link to a JavaScript equality table.
That's all for today's post, look ahead for my next entry, containing some tips and tricks for using Unobtrusive Client Validation in ASP.NET MVC
0 comments:
Post a Comment