Blog Post
(by @hckrmoon)
| const a = { prop: 'haha' }; | |
| console.log('prop => ', a.prop); // haha | |
| a.prop = 'hihi'; | |
| console.log('prop => ', a.prop); // hihi |
| const a = 'haha'; // a = 'haha' | |
| a = 'hihi'; // Assignment to constant variable |
| var a = 'hacker'; // a = 'hacker' | |
| var a = 'moon'; // a = 'moon' | |
| let b = 'hacker'; // b = 'hacker' | |
| let b = 'pinky'; // Identifier 'b' has already been declared |
| if (true) { | |
| console.log('a => ', a); // undefined | |
| console.log('b => ', b); // b is not defined | |
| var a = 'hacker'; | |
| let b = 'pinky'; | |
| } |
| if (true) { | |
| var a = 'hacker'; | |
| let b = 'moon'; | |
| console.log('a => ', a); // hacker | |
| console.log('b => ', b); // moon | |
| } | |
| console.log('a => ', a); // hacker | |
| console.log('b => ', b); // b is not defined |
| class Rational(n: Int, d: Int) { | |
| require(d != 0) | |
| private val g = gcd(n.abs, d.abs) | |
| val number = n /g | |
| val denom = d / g | |
| def this (n: Int) = this(n, 1) | |
| def + (that: Rational): Rational = |
| class Rational(x: Int, y: Int) { | |
| require(y != 0, "denominator must be nonzero"); | |
| def this(x: Int) = this(x, 1) | |
| private def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b) | |
| private val g = gcd(x, y) | |
| def numer = x / g | |
| def denom = y / g | |
Blog Post
(by @hckrmoon)
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| export default function combineReducers(reducers) { | |
| var reducerKeys = Object.keys(reducers) | |
| var finalReducers = {} | |
| for (var i = 0; i < reducerKeys.length; i++) { | |
| var key = reducerKeys[i] | |
| if (typeof reducers[key] === 'function') { | |
| finalReducers[key] = reducers[key] | |
| } | |
| } | |
| var finalReducerKeys = Object.keys(finalReducers) |