#Go over
- deferred promise pattern
- Factory, Service
- Directives
- Filters
#New
-
Events
-
DOM event http://www.w3schools.com/jsref/dom_obj_event.asp
document.addEventListener('myevent', function() { console.log('received 1'); }); document.addEventListener('myevent', function() { console.log('received 2'); }); document.dispatchEvent(new Event('myevent'));
-
AngularJS event https://docs.angularjs.org/guide/scope
angular.module('eventExample', []) .controller('EventController', ['$scope', function($scope) { $scope.count = 0; $scope.$on('MyEvent', function() { $scope.count++; }); //$emit('MyEvent'); //$broadcast('MyEvent'); }]);
-
ExtJS event
- Ext.util.Observable
- enableBubble
- addListener, addManagedListener, on, mon
- fireEvent
-
-
- compile to javascript languages
- CoffeeScript
- GWT
- Dart
- Many others
- Advantages
- Backed by Microsoft
- Developed by Anders Hejlsberg
- Superset of Javascript (use existing librarys)
- ECMAScript 6 standard (forward compatiblity)
- Relation with AngularJS
- Debugging
- compile to javascript languages
-
Install
- Node.js
- npm install -g typescript
-
Features
-
types: number, string, boolean, Array, Enum, Void, function, any
var num: number = 1; var str: string = 'string'; var bool: boolean = false; var arr: Array<string> = ['abc', 'ddd']; var arrNum: number[] = [1,2,3]; enum Day {SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY}; var day: Day = Day.MONDAY; var any: any = 3; any = 'foo'; var func: (a:number, b:number)=>number; function add(left: number, right: number): number { return left + right; } func = add;
-
Function
-
Optional parameters
function foo(param1: number, param2?: number) { // ... }
-
Default parameters values
function foo(param1: number, param2 = 0) { // ... }
-
-
Interface
-
Properties don't have to be in order
-
Properties must be present and match the types
-
Optional properties prop?: string
interface IFormController { /** * Indexer which should return ng.INgModelController for most properties but cannot because of "All named properties must be assignable to string indexer type" constraint - see https://github.com/Microsoft/TypeScript/issues/272 */ [name: string]: any; $pristine: boolean; $dirty: boolean; $valid: boolean; $invalid: boolean; $submitted: boolean; $error: any; $addControl(control: INgModelController): void; $removeControl(control: INgModelController): void; $setValidity(validationErrorKey: string, isValid: boolean, control: INgModelController): void; $setDirty(): void; $setPristine(): void; $commitViewValue(): void; $rollbackViewValue(): void; $setSubmitted(): void; $setUntouched(): void; }
-
-
Class
-
Members are public by default
-
Private members are only at compilation stage
class Animal { private foo: boolean; name:string; // public by default constructor(theName: string) { this.name = theName; } move(meters: number = 0) { alert(this.name + " moved " + meters + "m."); } } class Snake extends Animal { constructor(name: string) { super(name); } move(meters = 5) { alert("Slithering..."); super.move(meters); } } class Horse extends Animal { constructor(name: string) { super(name); } move(meters = 45) { alert("Galloping..."); super.move(meters); } } var sam = new Snake("Sammy the Python"); var tom: Animal = new Horse("Tommy the Palomino"); sam.move(); tom.move(34);
-
Lambda and this
return ()=> { //return function() { console.log(this); }
-
-
Module
- namespace, package
- export
-