View designpatterns-builder.ts
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
interface QueryBuilder { | |
table(table): QueryBuilder; | |
select(cols): QueryBuilder; | |
limit(value: Number): QueryBuilder; | |
where(col, value): QueryBuilder; | |
getQuery(): String; | |
/* +100 Other SQL Methods */ | |
} |
View designpatterns-abstract-factory.ts
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
interface Tablet { | |
switchOn(); | |
} | |
interface Smartphone { | |
switchOn(); | |
ring(); | |
} | |
class SamsungSmartphone implements Smartphone { |
View designpatterns-factory-method.ts
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
interface Vehicle { | |
setMode(mode); | |
move(); | |
} | |
abstract class Delivery { | |
public abstract makeVehicle(): Vehicle; | |
public handle() { | |
const vehicle = this.makeVehicle(); |
View typescript-open-closed-principle.ts
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
interface LanguageInterface { | |
sayHello(): string; | |
} | |
class Persian implements LanguageInterface { | |
public sayHello(): string { | |
return 'درود'; | |
} | |
} |
View typescript-dependency-injection.ts
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
interface Wheel {} | |
interface Engine {} | |
class Car { | |
private wheel: Wheel; | |
private engine: Engine; | |
public constructor(wheel: Wheel, engine: Engine) { | |
this.wheel = wheel; | |
this.engine = engine; |
View typescript-generics.ts
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 Queue<T> { | |
private data: T[] = []; | |
push(item: T) { | |
this.data.push(item); | |
} | |
pop(): T | undefined { | |
return this.data.shift(); | |
} |
View typescript-accessors.ts
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 User { | |
private rawUsername: string; | |
get userName(): string { | |
return "The fullname is: " + this.rawUsername; | |
} | |
set userName(newName: string) { | |
if (newName.length > 10) { | |
newName = newName.substr(0, 10); |
View typescript-simple-class.ts
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 { | |
name: string; | |
constructor(name: string) { | |
this.name = name; | |
} | |
sayHello(): string { | |
return `Hello ${this.name}, Welcome to Ditty.ir`; | |
} |
View javascript-push-object-into-local-storage.js
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 person = { | |
name: 'Bastian', | |
lastname: 'Schweinsteiger' | |
}; | |
person = JSON.stringify(person); | |
localStorage.setItem('user', person); | |
View javascript-hoisting.js
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
// These two lines: | |
console.log(y); // undefined | |
y = "Street"; | |
// are interpreted as: | |
var y; | |
console.log(y); // undefined | |
y = "Street"; |
NewerOlder