AngularJS Data Modeling

One of the great things about JavaScript really is the fact that you do not need a class to instantiate an object from.  One of the worst things about JavaScript is that you do not need a class to instantiate an object.

Most developers would agree that this is a big problem and blessing at the same time, especially if you come from an OOP background.  OOP in a MVC makes it really easy to standardise your objects and to reuse them all over your application.  In JavaScript, this is also a possibility, but how would you port this to AngularJS?

Continue reading

AngularJS: At your Service

Tutorials on Angular rarely focus on the importance of Services within your application.  Services will help you structure you app better and will promote code re-usability.  I really struggled to structure my apps, until I started making use of services.

As discussed in a previous post, there are many ways to instantiate a service, so we won’t go into that in this article.  The focus of this article is to help you rethink the way you are working with your controllers inside of AngularJS.

Controllers are not to be concerned with the structure of the data.  Controllers are to be used only to bring together functionality across multiple classes to perform a certain function.

Continue reading

AngularJS – $q promises

Handling asynchronous calls can deliver unexpected results.  This type of unexpected behaviour can be hard to track down but can be easily managed by means of promises.  Promises are to be released as part of ES6 (ECMAScript 6), but for now we are relying on external libraries to assist us with this task.

Fortunately does Angular provide a service for working with promises. $q.

Continue reading

JavaScript: The truth is rarely pure and never simple

Working with datatypes can be a tricky thing as it is.  But working with datatypes without having datatypes can be even more challenging.

One of the most misunderstood concepts in JavaScript is the concept of “falsy” and “truthy”.  Comparing types and values in JavaScript can have quite a different outcome than you might expect, especially if you have a strongly typed background.

It is however important to understand the differences, since it might lead to unexpected logic errors in your code.

Continue reading

To JavaScript, or not to JavaScript?

I remember when starting out with web development in 2003/2004, I was heavily confused with JavaScript. It was really a cumbersome language to learn, since it had great differences from other programming languages. And to add to it, was the problem of cross browser compatibility. Then came jQuery to save the day.

jQuery was a beautiful framework which added a lot of syntactical sugar on top of JavaScript. It did a lot of work for you regarding cross browser compatibility, but it also brought forth the problem of coders not understanding JavaScript any more.

JavaScript became a thing of the past. All you needed to know was some jQuery or any other framework of your choice. We soon started creating a culture of “Script Kiddies” who knew the frameworks, but doesn’t know how to put a framework together.

Continue reading