Skip to content

Instantly share code, notes, and snippets.

View wangdahoo's full-sized avatar
🎯
Focusing

王大虎 wangdahoo

🎯
Focusing
  • Shanghai
View GitHub Profile
@wangdahoo
wangdahoo / Logger.ts
Created November 29, 2019 17:01
Logger
enum LoggerLevel {
VERBOSE = 0,
DEBUG = 1,
INFO = 2,
WARN = 3,
ERROR = 4
}
enum ConsoleMethod {
log = 'log',
@wangdahoo
wangdahoo / redux.js
Created April 22, 2020 16:11
Tiny Redux in 40 Lines
// Tiny Redux
export const combineReducers = reducers => {
return (state = {}, action) => {
return Object.keys(reducers).reduce(
(nextState, key) => {
nextState[key] = reducers[key](state[key], action)
return nextState
},
{}
@wangdahoo
wangdahoo / parasitic-composition-inheritance.js
Created July 21, 2020 13:43
Parasitic Composition Inheritance
// 寄生组合继承 (相对完美的继承范式)
// 父类
function Animal (name) {
// 实例方法
this.name = name
this.sleep = function () {
console.log(`${this.name} is sleeping...`)
}