typed – Static typing for JavaScript

About two weeks ago I first read about TypeScript, Microsoft´s version of a statically typed language which compiles to JavaScript. Besides the static typing which I´ve actually never missed in JS it supports classes, modules and interfaces. The class keyword is syntactic sugar (like in ES6) and the modules compile down to plain old namespaces. So nothing too special there. However the interface concept looks quite interesting. I actually would like to use interfaces in JavaScript from time to time. But I won´t bother switching to another language which I have to compile just to be able to use them.

Continue reading

JavaScript module formats

What would life be without any contradictions? Although I announced that my blog posts will be much shorter in future here is probably the longest one I´ve ever written :D About one and a half year ago I first got in touch with modularization possibilites in JavaScript. Since then I have worked extensively with namespaces, the Asynchronous Module Definition (AMD) and CommonJS Modules (implemented in Node.js). Today I consider myself pretty skilled in using any of these formats and therefore I want to share with you their pros and cons.

Continue reading

Grunt – a build tool for JavaScript projects

I wasn´t really sure if I wanted to continue writing blog posts. Now I have finally decided to do so and have also realized what has stopped me until now: I invested way too much time in trying to publish well written and informative blog posts. I´m already spending enough time on developing, reading blogs and experimenting with new technologies. So from now on my posts will just be way shorter (and maybe full of typos). Let´s see how that goes.

Recently I got to know Grunt, a “task-based command line build tool for JavaScript projects”. I already converted declarative to use Grunt and have to say it works really great. Its tasks can take care of all that linting, test execution, combining, minification, etc. in an automated way. One task worth to mention is grunt-jasmine-task which executes all Jasmine specs in PhantomJS.

Grunt is also really easy to extend by writing custom tasks. I have already written two myself: grunt-umd to surround code with the universal module definition and grunt-reznik to integrate reznik for AMD dependency analysis. There is also an official collection of contributed grunt tasks available here.

If you are working on some JavaScript project you probably should also be using Grunt.

Testability of DOM ready handlers

I bet you already thought this blog was dead because I didn´t come up with something new for quite a while. You were wrong, here I am again! :) Other than the previous posts about general stuff this one is more code related. It is about the testability of jquery DOM ready handlers.

A DOM ready handler is a function that is passed to jquery and executed as soon as the DOM is fully loaded (put simplified). If the DOM is already loaded by the time registering the handler, the function is executed immediately. You can read about the details of this mechanism here. In most cases such handlers are defined as anonymous functions:

Continue reading