The Malta Business Weekly

Making backend developers comfortabl­e with JavaScript

If you’re a backend developer, then you will have worked on or come across .NET Framework with all its capabiliti­es and powerful tools.

-

used to and the compiler produces the JavaScript that accomplish­es the intent. However, backend developers have been hesitant to really get into JavaScript due to its loose approach to object definition.

In the TypeScript editor, you can’t add an additional property without getting a warning. Constructo­rs, though available in JavaScript, are enhanced with the TypeScript tooling, again by enforcing the creation of the object during compile time and not allowing the object to be created without passing in the proper elements and types in the call. Not only can you add the constructo­r to the class, but you can make the parameters optional, set a default value or shortcut the property declaratio­n. Classes in TypeScript also provide inheritanc­e. A helper class usually assists in the inheritanc­e functional­ity. As a side note, this helper function has the exact same signature regardless of the source, so if you’re organising your JavaScript in multiple files and use a utility such as SquishIt or Web Essentials to combine your scripts, you might get an error depending on how the utility rectifies duplicated functions.

Modules in TypeScript are the equivalent of namespaces in the .NET Framework. They’re a great way to organise your code and to encapsulat­e business rules and processes that would not be possible without this functional­ity (JavaScript doesn’t have a built-in way to provide this function). The module pattern, or dynamic namespacin­g, as in JQuery, is the most common pattern for namespaces in JavaScript. TypeScript modules simplify the syntax and produce the same effect.

Another nice benefit of modules is that you can merge them. If you create another module, TypeScript assumes that the code in the first module and the code in new module are both accessible through statements, just as in namespaces. Modules facilitate the maintainab­ility and organisati­on of your code. With them, sustaining large-scale applicatio­ns becomes less of a burden on developmen­t teams.

The features TypeScript adds to JavaScript developmen­t are small, but yield large benefits to backend developers who are accustomed to similar features in the languages they use for regular Windows applicatio­n developmen­t.

TypeScript is not a silver bullet and it’s not intended to be, but for anyone hesitant to jump into JavaScript, TypeScript is a great language that can ease the journey.

 ??  ??
 ??  ??
 ??  ??

Newspapers in English

Newspapers from Malta