随笔分类 -  Javascript

摘要:Take away:Always check you ruturn the accumulatorAlways pass in the inital valuevar data = ["vote1", "vote2", "vote1", "vote2"];var reducer = function... 阅读全文
posted @ 2015-12-01 01:31 Zhentiw
摘要:Sometimes we need to turn arrays into new values in ways that can't be done purely by passing an accumulator along with no knowledge about its context... 阅读全文
posted @ 2015-11-30 20:30 Zhentiw
摘要:Learn how to use Object.assign() and the spread operator proposed for ES7 to avoid mutating objects./* * Open the console to see * that the tests have... 阅读全文
posted @ 2015-11-30 03:31 Zhentiw
摘要:Learn how two common array functions - map() and filter() - are syntactic sugar for reduce operations. Learn how to use them, how to compose them, and... 阅读全文
posted @ 2015-11-29 18:00 Zhentiw
摘要:For Redux, you cannot use mutable methods like push, splice. Need to use immutable methods such as concat, slice and ...spreadHtml: JS Bin push(... 阅读全文
posted @ 2015-11-29 01:29 Zhentiw
摘要:Currying is a core concept of functional programming and a useful tool for any developer's toolbelt.Example 1:let f = a => b => c => a+b+c;let result ... 阅读全文
posted @ 2015-11-29 00:50 Zhentiw
摘要:Array slice creates a shallow copy of an array. In this lesson we cover, in detail, exactly what a 'shallow' copy is and how it can trip people up. We... 阅读全文
posted @ 2015-11-27 03:50 Zhentiw
摘要:Before you use the React Redux bindings, learn how to create a complete simple application with just React and Redux. JS Bin const counter = ... 阅读全文
posted @ 2015-11-26 03:38 Zhentiw
摘要:Learn how to build a reasonable approximation of the Redux Store in 20 lines. No magic!const counter = (state = 0, action) => { switch (action.type) ... 阅读全文
posted @ 2015-11-26 02:12 Zhentiw
摘要:console.clear();const counter = (state = 0, action) => { switch (action.type) { case 'INCREMENT': return state + 1; case 'DECREMENT': ... 阅读全文
posted @ 2015-11-25 03:17 Zhentiw
摘要:Single immutable state tree: Should be just one single javascript object.Describing the changes by action: every change in the application state as ... 阅读全文
posted @ 2015-11-25 03:03 Zhentiw
摘要:Recursion is a technique well suited to certain types of tasks. In this first lesson we’ll look at solving a problem that requires the flattening of a... 阅读全文
posted @ 2015-11-24 02:49 Zhentiw
摘要:Best Pratices for Object.assign: http://www.cnblogs.com/Answer1215/p/5096746.html Object.assign() can extend the object by adding new props: let obj = 阅读全文
posted @ 2015-11-12 03:13 Zhentiw
摘要:An introduction to the Web Audio API. In this lesson, we cover creating an audio context and an oscillator node that actually plays a sound in the bro... 阅读全文
posted @ 2015-11-11 01:47 Zhentiw
摘要:To Currencyfunction toCurrency(price){ return price.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,");}Deletion from Array:function deleteValues(a... 阅读全文
posted @ 2015-11-02 02:48 Zhentiw
摘要:Learn how to query an Immutable.Map() using get, getIn, has, includes, find, first and last. These are powerful operators that make finding data in an... 阅读全文
posted @ 2015-10-18 19:42 Zhentiw
摘要:We will now look at five methods that modify an Immutable.Map().setupdatedeleteclearmerge//set()var map = Immutable.Map();var todo = { id: +new Date(... 阅读全文
posted @ 2015-10-18 18:16 Zhentiw
摘要:Learn how to create an Immutable.Map() through plain Javascript object construction and also via array tuples.console.clear();// Can be an objectvar m... 阅读全文
posted @ 2015-10-18 17:55 Zhentiw
摘要:Learn how Immutable.js data structures are different from native iterable Javascript data types and why they provide an excellent foundation on which ... 阅读全文
posted @ 2015-10-15 02:36 Zhentiw