Last active
February 9, 2018 17:54
-
-
Save carlosvega20/5fa241af1730b9271d83 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Hablar sobre variables(fuerte tipado), | |
luego funciones (como se crean function, var function, arrow function), | |
luego scopes (var, const, let) | |
luego variables como templates | |
Classes, interfaces, herencia (polimorfismo, encapsulamient) | |
luego hablar sobre OOP con classes y extend | |
vs functional programing( fp are verbs, oop is nouns) | |
***Arrow Function Expression*** | |
ES5 | |
(function (a,b) | |
{ | |
return a+b; | |
})(1,2); | |
[1,2,3].map(function(el){ | |
return el+1; | |
}); | |
ES6 | |
((a,b)=>a+b)(1,2) | |
[1,2,3].map(el=>el+1); | |
***Default Values*** | |
ES5 | |
function sum (a, b) { | |
var b = b || 0; | |
return a+b; | |
} | |
ES6 | |
var sum = ((a,b=0)=>a+b); | |
***Rest Parameters*** | |
ES5 | |
function sum (){ | |
return Array.prototype.slice.call(arguments).reduce(function (a,b) {return a+b;}); | |
} | |
ES6 | |
var sum = ((...numbers)=>numbers.reduce((a,b)=>a+b)) | |
***Spread*** | |
ES5 | |
sum.apply(undefined, [1,2,3,4]) | |
ES6 | |
sum(...[1,2,3,4]) | |
////Still in progress i dont completed understand it | |
//const config = require('../config'); | |
//import config from '../config'; | |
//Same as range | |
Array(8).fill().map((_, i) => i * i); | |
***Define a type*** | |
var myString:string; | |
var myWhatever:any; | |
var myUnknown:T; | |
var myComplexObject:{x:number, y:number}; | |
var myStringArray:string[]; | |
var myArrayofNums:Array<number>; | |
var myMatrix:Array<Array<myComplexObject>>; | |
var myFun:(some:number)=>number; | |
***func parameters *** | |
function myFunc (arg:string, arg2:number, arg3?:Array<>, arg4:string='default'):void { | |
} | |
use a variable to declare a function type | |
var myTypeSchema:(arg:string, arg2:number, arg3?:Array<>)=>void; | |
var myFunc:myTypeSchema = (a,b) => console.log('no retorna'); | |
***Classes***** | |
class BaseClass { | |
static getVersion():string {return "v.1.0"}; | |
constructor(public arg:string, privade arg2:string){} | |
} | |
interface myInterface { | |
property1:string; | |
myFunc(arg:string, arg2:number):number; | |
} | |
class ClassName extends BaseClass implement myInterface { | |
static getVersion():string{return super.getVersion() + " beta";}; | |
other:boolean; // properties are made public by default | |
myFunc(f:string, d:number){return 22;} | |
constructor(public a:string) {super(a, 'hola'); this.other = true;} | |
} | |
//Call a static method | |
var classVersion = ClassName.getVersion(); | |
//Instance | |
var classInstance:ClassName = new ClassName("my Class"); | |
classInstance.myFunc("ss", "ddd"); | |
***Interfaces**** | |
var myJSON:myInterface = {property1:"test", myFunc:myfff(arg:string, arg2:string):number=>33} | |
***Module**** | |
*** Imports *** | |
example abstract class and interface | |
interface Activatable { | |
ActivateSelf: () => void; | |
} | |
abstract class AbstractBase implements Activatable{ | |
private _myName: string; | |
public get Name() { return this._myName; } | |
constructor (name: string) { | |
this._myName = name; | |
} | |
abstract ActivateSelf(): void; | |
} | |
class ArmyBase extends AbstractBase { | |
private _totalSolders: number; | |
public get TotalSolders() { return this._totalSolders; } | |
constructor(name: string, totalSolders: number) { | |
super(name); | |
this._totalSolders = totalSolders; | |
} | |
public ActivateSelf() { | |
throw "Not yet implemented"; | |
} | |
} | |
class NavyBase extends AbstractBase { | |
private _totalShips: number; | |
public get TotalShips() { return this._totalShips; } | |
constructor(name: string, totalShips: number) { | |
super(name); | |
this._totalShips = totalShips; | |
} | |
public ActivateSelf() { | |
throw "Not yet implemented"; | |
} | |
} | |
const armyBase = new ArmyBase("First army base", 100); | |
const navyBase = new NavyBase("First navy base", 3); | |
const anotherArmyBase: Activatable = new ArmyBase("Second army base", 250); | |
// Compiler throws an error - abstract classes can not be instantiated: | |
const someOtherKindOfBase = new AbstractBase("what kind of base is this?"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment