Skip to content

Instantly share code, notes, and snippets.

View hoangtranson's full-sized avatar
🎯
Focusing

Hoang Tran Son hoangtranson

🎯
Focusing
View GitHub Profile
@hoangtranson
hoangtranson / arrowFunction.js
Created August 4, 2019 13:37
arrow function in javascript
//function expression
const hello = function() {
return "Hello World!";
}
// arrow function with return
const hello = () => {
return "Hello World!";
}
@hoangtranson
hoangtranson / method.js
Created August 4, 2019 14:07
sample method in javascript
const obj = {
foo: function() {
/* code */
},
bar: function() {
/* code */
}
};
// from ES2015 it can shorten to
@hoangtranson
hoangtranson / generator.js
Created August 8, 2019 10:06
generator function
function* generator(i) {
yield i;
yield i + 10;
}
@hoangtranson
hoangtranson / app.module.ts
Created August 13, 2019 07:16
config translation by ngx-translate
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import {TranslateLoader, TranslateModule} from '@ngx-translate/core';
import {TranslateHttpLoader} from '@ngx-translate/http-loader';
import {HttpClient, HttpClientModule} from '@angular/common/http';
@NgModule({
@hoangtranson
hoangtranson / AppComponent.ts
Created August 13, 2019 07:17
AppComponent with ngx-translate
import {Component} from '@angular/core';
import {TranslateService} from '@ngx-translate/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
constructor(private translate: TranslateService) {
@hoangtranson
hoangtranson / classSample.js
Last active August 17, 2019 14:03
sample sub class in javascript
class Animal {
constructor(name) {
this.name = name;
}
speak() {
console.log(`${this.name} makes a noise.`);
}
}
@hoangtranson
hoangtranson / class.js
Created August 17, 2019 14:08
sub class from function based classes
function Animal (name) {
this.name = name;
}
Animal.prototype.speak = function () {
console.log(`${this.name} makes a noise.`);
}
class Dog extends Animal {
eat() {
@hoangtranson
hoangtranson / class1.js
Created August 17, 2019 14:12
Use Object.setPrototypeOf() in case of extending regular objects.
const Animal = {
speak() {
console.log(`${this.name} makes a noise.`);
}
};
class Dog {
constructor(name) {
this.name = name;
}
@hoangtranson
hoangtranson / class2.js
Created August 17, 2019 14:15
Super class calls with super
class Animal {
constructor(name) {
this.name = name;
}
speak() {
console.log(`${this.name} makes a noise.`);
}
}
@hoangtranson
hoangtranson / mixin.js
Created August 18, 2019 13:20
simple mixin in javascript
const animalBehavior = {
speak() {
console.log(`${this.name} makes a noise.`);
},
eat() {
console.log('Yummy Yummy!');
}
}
class Dog {