Last active
April 5, 2017 02:50
-
-
Save jawache/f4e54b8540ed2674d34629047959a6ab to your computer and use it in GitHub Desktop.
typescriptcrashcourse
This file contains 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
let obj = { | |
name: "Asim", | |
sayLater: function() { | |
// this... | |
setTimeout(() => console.log(`${this.name}`), 1000) | |
} | |
}; | |
obj.sayLater(); |
This file contains 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
'use strict'; | |
const foo = Object.freeze({}); | |
foo.prop = 1; | |
console.log(foo.prop); | |
This file contains 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
// const arr = ['a', 'b']; | |
// const [x, y] = arr; | |
// console.log(x); | |
// console.log(y); | |
function func({x=1}) { | |
console.log(x); | |
} | |
func({}); | |
// const obj = {first: 'Asim', last: 'Hussain', age: 39 }; | |
// | |
// function getObj() { | |
// return obj; | |
// } | |
// | |
// const {first, last} = getObj(); | |
// | |
// console.log(first); | |
// console.log(last); | |
This file contains 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
'use strict'; | |
let funcs = []; | |
for (let i = 0; i < 10; i += 1) { | |
funcs.push(function () { | |
console.log(i); | |
}) | |
} | |
funcs.forEach(function (func) { | |
func() | |
}); | |
// var a = "global"; | |
// function hello() { | |
// var a = "function"; | |
// for (var i = 0; i < 10; i++) { | |
// let a = "block"; | |
// } | |
// console.log(a); | |
// } | |
// hello(); |
This file contains 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
let name = "Asim"; | |
let single = `hello | |
world | |
my | |
name | |
is | |
${name}`; | |
console.log(single); |
This file contains 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
class Person { | |
constructor(firstName, lastName) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
} | |
name() { | |
return `${this.firstName} ${this.lastName}`; | |
} | |
whoAreYou() { | |
return `Hi i'm ${this.name()}`; | |
} | |
} | |
class Student extends Person { | |
constructor(firstName, lastName, course) { | |
super(firstName, lastName); | |
this.course = course; | |
} | |
whoAreYou() { | |
return `${super.whoAreYou()} and i'm studying ${this.course}`; | |
} | |
} | |
let asim = new Student("Asim", "Hussain", "typescript"); | |
console.log(asim.whoAreYou()); |
This file contains 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
class Person { | |
constructor(private firstName, private lastName) { | |
} | |
public name() { | |
return `${this.firstName} ${this.lastName}`; | |
} | |
protected whoAreYou() { | |
return `Hi i'm ${this.name()}`; | |
} | |
} | |
class Student extends Person { | |
course; | |
constructor(firstName, lastName, course) { | |
super(firstName, lastName); | |
this.course = course; | |
} | |
whoAreYou() { | |
return `${super.whoAreYou()} and i'm studying ${this.course}`; | |
} | |
} | |
let asim = new Student("Asim", "Hussain", "typescript"); | |
console.log(asim.whoAreYou()); |
This file contains 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
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | |
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; | |
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); | |
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; | |
return c > 3 && r && Object.defineProperty(target, key, r), r; | |
}; | |
function Student(config) { | |
return function (target) { | |
Object.defineProperty(target.prototype, 'course', { value: function () { return config.course; } }); | |
}; | |
} | |
var Person = (function () { | |
function Person(firstName, lastName) { | |
this.firstName = firstName; | |
this.lastName = lastName; | |
} | |
Person.prototype.name = function () { | |
return this.firstName + " " + this.lastName; | |
}; | |
Person.prototype.whoAreYou = function () { | |
return "Hi i'm " + this.name(); | |
}; | |
Person = __decorate([ | |
Student({ | |
course: "angular3" | |
}) | |
], Person); | |
return Person; | |
}()); | |
var asim = new Person("Asim", "Hussain"); | |
console.log(asim.course()); |
This file contains 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
function Student(config) { | |
return function (target) { | |
Object.defineProperty(target.prototype, 'course', {value: () => config.course}) | |
} | |
} | |
@Student({ | |
course: "angular3" | |
}) | |
class Person { | |
constructor(private firstName, private lastName) { | |
} | |
public name() { | |
return `${this.firstName} ${this.lastName}`; | |
} | |
protected whoAreYou() { | |
return `Hi i'm ${this.name()}`; | |
} | |
} | |
let asim = new Person("Asim", "Hussain"); | |
console.log(asim.course()); |
This file contains 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
console.log("hello world 2!"); |
This file contains 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
console.log("hello world 2!"); |
This file contains 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
"use strict"; | |
function square(x) { | |
return Math.pow(x, 2); | |
} | |
Object.defineProperty(exports, "__esModule", { value: true }); | |
exports.default = square; | |
function cow() { | |
console.log("Mooooo!!!"); | |
} | |
exports.cow = cow; |
This file contains 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
export default function square(x) { | |
return Math.pow(x,2) | |
} | |
export function cow() { | |
console.log("Mooooo!!!") | |
} |
This file contains 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
"use strict"; | |
var module1_1 = require('./module1'); | |
console.log(module1_1.default(4)); | |
module1_1.cow(); |
This file contains 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
import square, {cow} from './module1'; | |
console.log(square(4)); | |
cow(); |
This file contains 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
{ | |
"compilerOptions": { | |
"module": "commonjs", | |
"target": "es5", | |
"noImplicitAny": false, | |
"sourceMap": false | |
}, | |
"exclude": [ | |
"node_modules" | |
] | |
} |
This file contains 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
var Direction; | |
(function (Direction) { | |
Direction[Direction["Up"] = 0] = "Up"; | |
Direction[Direction["Down"] = 1] = "Down"; | |
Direction[Direction["Left"] = 2] = "Left"; | |
Direction[Direction["Right"] = 3] = "Right"; | |
})(Direction || (Direction = {})); | |
var a = 1; | |
a = "2"; |
This file contains 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
enum Direction { | |
Up, | |
Down, | |
Left, | |
Right | |
} | |
let a = 1; | |
a = "2"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment