This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app => application | |
acc => accumulate | |
arr => array | |
abs => absolute | |
addr => address | |
arg => argument | |
args => arguments | |
attr => attribute | |
attrs => attributes | |
auth => authenticate |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reduce(f, acc, iter) { | |
if (arguments.length == 2) { | |
iter = acc[Symbol.iterator](); | |
acc = iter.next().value; | |
} | |
for (const a of iter) acc = f(acc, a); | |
return acc; | |
} | |
reduce((a, b) => a + b, function*() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ES6 | |
function* foo(){ | |
yield bar(); | |
} | |
// ES5 Compiled | |
"use strict"; | |
var _marked = /*#__PURE__*/ regeneratorRuntime.mark(foo); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ES7 | |
async function foo() { | |
await bar(); | |
} | |
// ES5 complied | |
let foo = (() => { | |
var _ref = _asyncToGenerator(function*() { | |
yield bar(); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function* idMaker(){ | |
var index = 0; | |
while(index < 3) | |
yield index++; | |
} | |
const gen = idMaker(); | |
console.log(gen.next().value); // 0 | |
console.log(gen.next().value); // 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const arr = []; | |
for(let i=0; i<100; i++) { | |
arr.push(0); | |
} | |
console.log(arr); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const iterable = { | |
[Symbol.iterator]() { | |
return { | |
i: 0, | |
next() { | |
if (this.i < 3) { | |
return { value: this.i++, done: false }; | |
} | |
return { value: undefined, done: true }; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* array */ | |
let iterable = [10, 20, 30]; | |
for (let value of iterable) { | |
console.log(value); // 10 20 30 | |
} | |
/* string */ | |
let iterable = "boo"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// react | |
const handleChange = (fieldName) => (event) => {aveField(fieldName, event.target.value)} | |
<input type="text" onChange={handleChange('email')} ... /> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getters: { | |
// ... | |
getTodoById: (state, getters) => (id) => { | |
return state.todos.find(todo => todo.id === id) }} | |
store.getters.getTodoById(2) // -> { id: 2, text: '...', done: false } |
NewerOlder