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
| let arr = ['a', 'b', 'c']; | |
| Object.keys(arr).forEach(key => { | |
| console.log(key) | |
| }); |
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
| // using Array.from | |
| let array = Array.from(mySet); | |
| // simply spreading the Set out in an array | |
| let array = [...mySet]; |
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
| // npm install --save electron-localshortcut | |
| const electronLocalshortcut = require('electron-localshortcut'); | |
| const BrowserWindow = require('electron').BrowserWindow; | |
| const win = new BrowserWindow(); | |
| win.loadUrl('https://github.com'); | |
| win.show(); | |
| electronLocalshortcut.register(win, 'Ctrl+A', () => { |
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
| let events = require('events'); | |
| let eventEmitter = new events.EventEmitter(); | |
| let ringBell = () => { | |
| console.log('ring ring ring'); | |
| } | |
| eventEmitter.on('doorOpen', ringBell); | |
| eventEmitter.emit('doorOpen'); |
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
| find /path/to/dir -name "filename" | |
| find /path/to/dir -name "*.h" |
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
| // includes() startsWith() endsWith() | |
| s = 'Hello world!' | |
| s.includes('o') // true | |
| s.startsWith('Hello') // true | |
| s.endsWith('!') // true | |
| // 这三个方法都支持第二个参数,表示开始搜索的位置。 | |
| s.includes('Hello', 6) // false | |
| s.startsWith('world', 6) // 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.from方法用于将两类对象转为真正的数组: | |
| 1. 类似数组的对象(array-like object) | |
| 2. 可遍历(iterable)的对象(包括ES6新增的数据结构Set和Map)*/ | |
| // example1 | |
| let arrayLike = { '0': 'a', '1': 'b', '2': 'c', length: 3 } | |
| let arr2 = Array.from(arrayLike); // ['a', 'b', 'c'] | |
| // example 2 | |
| Array.from('hello') // ['h', 'e', 'l', 'l', 'o'] |
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允许使用“箭头”(=>)定义函数。注意的是,箭头函数会自动绑定this。*/ | |
| // 如果箭头函数不需要参数或需要多个参数,就使用一个圆括号代表参数部分。 | |
| let sum = (num1, num2) => num1 + num2 | |
| // 等同于 | |
| let sum = function(num1, num2) { | |
| return num1 + num2 | |
| } | |
| // 如果箭头函数的代码块部分多于一条语句,就要使用大括号将它们括起来,并且使用return语句返回。 |
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
| /* 向Set加入值的时候,不会发生类型转换,所以5和"5"是两个不同的值。 Set内部判断 | |
| 两个值是否不同,使用的算法叫做“Same-value equality”,它类似于精确相等运算符 | |
| (===),主要的区别是NaN等于自身,而精确相等运算符认为NaN不等于自身。*/ | |
| // 例一 | |
| let set = new Set([1, 2, 3, 4, 4]) | |
| [...set] // [1, 2, 3, 4] | |
| // 例二 | |
| let items = new Set([1, 2, 3, 4, 5, 5, 5, 5]) |
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
| let m = new Map() | |
| let o = {p: 'Hello World'} | |
| m.set(o, 'content') | |
| m.get(o) // "content" | |
| m.has(o) // true | |
| m.delete(o) // true | |
| m.has(o) // false |