Inheritance – Angular 1 versus Backbone

Inheritance is a very powerful feature of object-oriented programming, and is also a fundamental concept when using JavaScript frameworks. Using a Backbone controller or an Angular 1 controller within the framework relies on certain characteristics or functions being available. We have seen, however, that each framework implements inheritance in a different way.

As JavaScript (prior to EC6) did not have the concept of inheritance, each of these older frameworks needed to find a way to implement it. In Backbone, this inheritance implementation is via the extend function of each Backbone object. As we have seen, the TypeScript extends keyword follows a similar implementation to Backbone, allowing the framework and language to dovetail each other.

Angular 1, on the other hand, uses its own implementation of inheritance, and defines functions on the Angular 1 global namespace to create classes (that is, angular.module). We can also sometimes use the instance of an application (that is, <appName>.controller) to create modules or controllers. We have found, though, that Angular 1 uses controllers in a very similar way to TypeScript classes, and we can therefore simply create standard TypeScript classes that will work within an Angular 1 application.

So far, we have only skimmed the surface of both the Angular 1 TypeScript syntax and the Backbone TypeScript syntax. The point of this exercise was to try and understand how TypeScript can be used within each of these two older third-party frameworks.

Be sure to visit http://todomvc.com, and have a look at the full source code for the Todo application written in TypeScript for both Angular 1 and Backbone. They can be found on the Compile-to-JS tab in the example section. These running code samples, combined with the documentation on each of these sites, will prove to be an invaluable resource when trying to write TypeScript syntax with an older external third-party library, such as Angular 1 or Backbone.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.224.149.242