使用箭头函数简单实现高阶函数扁平化 const setValue = id => value =>document.getElementById(id).value = value; const setHtml = id => value => document.getElementById(id).innerHTML = value;
来个复杂一点的看看是什么样子?
const infoAction = {type: 'ADD_INFO', payload: {name: 'Brian', framework: 'Angular'}} const anotherPersonInfo = person(undefined, infoAction); const hoursWorked = (state = 0, action) => { switch(action.type){ case 'ADD_HOUR': return state + 1; case 'SUBTRACT_HOUR': return state - 1; default: return state; } } const myReducers = {person, hoursWorked}; const combineReducers = reducers => (state = {}, action) => { return Object.keys(reducers).reduce((nextState, key) => { nextState[key] = reducers[key](state[key], action); return nextState; }, {}); }; const rootReducer = combineReducers(myReducers); const firstState = rootReducer(undefined, {type: 'ADD_INFO', payload: {name: 'Brian'}}); const secondState = rootReducer({hoursWorked: 10, person: {name: 'Joe'}}, {type: 'ADD_HOUR'});能说出最后输出的结果是啥吗?
JSON内部可以直接书写不带function后缀的函数 const tools = { isMobile(){}, isCard(){}, isAndroid(){}, isPc(){} } 使用default与不使用default声明的区别 1 export class Application{} 2 export default class Application{}以上类的声明在使用的时候有什么区别?
1 import { Application } from './app.ts'; 2 import Application from './app.ts'; 使用自动属性GET/SET export class UserInfo{ _name: string = 'mntx'; set name(name){ this._name = name; } get name(){ return this._name; } }未完待续
天之骄子
2017.8.13 深圳 星期日
查看原文: 人人都要学会使用的ES6语法与技巧