December 2016
Intermediate to advanced
841 pages
17h
English
Now that we have learned how to use the basic TypeScript building blocks individually, let's take a look at a final example in which we will use modules, classes, functions, and type annotations for each of these elements:
module Geometry{ export interface Vector2dInterface { toArray(callback : (x : number[]) => void) : void; length() : number; normalize(); } export class Vector2d implements Vector2dInterface { private _x: number; private _y : number; constructor(x : number, y : number){ this._x = x; this._y = y; } toArray(callback : (x : number[]) => void) : void{ callback([this._x, this._y]); } length() : number{ return Math.sqrt(this._x * this._x + this._y * this._y); } normalize(){ var len = 1 / this.length(); this._x ...Read now
Unlock full access