Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anterior Revisión previa Próxima revisión | Revisión previa | ||
|
wiki2:typescript [2016/07/17 08:07] alfred [Functions with return type] |
wiki2:typescript [2020/05/09 09:25] (actual) |
||
|---|---|---|---|
| Línea 2: | Línea 2: | ||
| ===== Basics ===== | ===== Basics ===== | ||
| + | ==== Foreach ==== | ||
| + | <code javascript> | ||
| + | for (var item of someArray) { | ||
| + | console.log(item); // 9,2,5 | ||
| + | } | ||
| + | </code> | ||
| + | |||
| ==== Functions with return type ==== | ==== Functions with return type ==== | ||
| <code javascript> | <code javascript> | ||
| Línea 9: | Línea 16: | ||
| </code> | </code> | ||
| + | ==== Getters ==== | ||
| + | <code javascript> | ||
| + | get whereSendContent () { | ||
| + | return `${AppConfig.ServerUrl}'/content`; | ||
| + | } | ||
| + | </code> | ||
| ===== Classes ===== | ===== Classes ===== | ||
| ==== Inheritance ==== | ==== Inheritance ==== | ||
| Línea 41: | Línea 54: | ||
| sam.move(); | sam.move(); | ||
| tom.move(34); | tom.move(34); | ||
| + | </code> | ||
| + | |||
| + | ==== Static properties ==== | ||
| + | <code javascript> | ||
| + | class Grid { | ||
| + | static origin = {x: 0, y: 0}; | ||
| + | calculateDistanceFromOrigin(point: {x: number; y: number;}) { | ||
| + | let xDist = (point.x - Grid.origin.x); | ||
| + | let yDist = (point.y - Grid.origin.y); | ||
| + | return Math.sqrt(xDist * xDist + yDist * yDist) / this.scale; | ||
| + | } | ||
| + | constructor (public scale: number) { } | ||
| + | } | ||
| + | |||
| + | let grid1 = new Grid(1.0); // 1x scale | ||
| + | let grid2 = new Grid(5.0); // 5x scale | ||
| + | |||
| + | console.log(grid1.calculateDistanceFromOrigin({x: 10, y: 10})); | ||
| + | console.log(grid2.calculateDistanceFromOrigin({x: 10, y: 10})); | ||
| + | </code> | ||
| + | |||
| + | ===== Others ===== | ||
| + | |||
| + | ==== Use JavaScript ==== | ||
| + | First we need to tell that exists some variable with the needed name there: | ||
| + | <code> | ||
| + | declare let BootstrapDialog: any; | ||
| + | |||
| + | @Component({ | ||
| + | ... | ||
| + | </code> | ||
| + | Then we can use it on its code (to intercept callbacks: ''onComplete: () => { this.chartTestMethod(); }'' | ||
| + | <code javascript> | ||
| + | BootstrapDialog.show({ | ||
| + | message: 'Hi Apple!', | ||
| + | type: BootstrapDialog.TYPE_WARNING, | ||
| + | buttons: [{ | ||
| + | label: 'Button 2', | ||
| + | cssClass: 'btn-primary', | ||
| + | action: (dialogItself: any) => { | ||
| + | this.deleteMission(dialogItself); | ||
| + | } | ||
| + | }, { | ||
| + | icon: 'glyphicon glyphicon-ban-circle', | ||
| + | label: 'Button 3', | ||
| + | cssClass: 'btn-warning' | ||
| + | }, { | ||
| + | label: 'Close', | ||
| + | action: function(dialogItself: any){ | ||
| + | dialogItself.close(); | ||
| + | } | ||
| + | }] | ||
| + | }); | ||
| </code> | </code> | ||