This file contains 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() { | |
let canvas = document.querySelector('canvas'); | |
// Optional frames per second argument. | |
let stream = canvas.captureStream(25); | |
let recorder = new MediaRecorder(stream, options); | |
let blobs = []; | |
function download(blob) { | |
var url = window.URL.createObjectURL(blob); | |
var a = document.createElement('a'); |
This file contains 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 original = [0,1,2,3]; | |
const copy = Object.assign([], original, { 2: 42 }); // [0,1,42,3] | |
console.log(original); | |
// [ 0, 1, 2, 3 ] | |
console.log(copy); | |
// [ 0, 1, 42, 3 ] |
This file contains 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 WhySoManyProps(props) { | |
const user = extractUser(props); | |
const fudge = calculateFudge(); | |
const bits = computeBits(); | |
// This is soooooo redundant. | |
return <SomeComponent user={user} fudge={fudge} bits={bits} />; | |
} | |
function Shorthand(props) { |
This file contains 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 moment = require('moment'); | |
const PERIOD = moment.duration(3, 'days'); | |
module.exports = { | |
PERIOD, | |
isWithinPeriod(test) { | |
return moment().add(PERIOD).isAfter(test); | |
}, | |
}; |
This file contains 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
#!/usr/bin/env node | |
// skip the first two args as they are node and this script | |
const [,,filepath] = process.argv; | |
doSomethingFSLike(filepath); |
This file contains 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 { | |
topLevel: { | |
intermediate, // declaration of intermediate | |
intermediate: { | |
nested // declaration of nested | |
} | |
} | |
} = { | |
topLevel: { | |
intermediate: { |
This file contains 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 defaults({ a = 1, b = 2 } = {}) { | |
console.log('a', a); | |
console.log('b', b); | |
} | |
defaults(); | |
// a 1 | |
// b 2 | |
defaults({ a: 42, b: 32 }); |
This file contains 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 defaults({ a, b } = { a: 1, b: 2 }) { | |
console.log('a', a); | |
console.log('b', b); | |
} | |
defaults(); | |
// a 1 | |
// b 2 | |
defaults({ a: 42, b: 32 }); |
This file contains 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
// simple renaming to avoid collisions or just as a preference. | |
const a = 5; | |
const { a: b } = { a: 3 }; | |
console.log(b); // prints 3 | |
// rename for another API and use enhanced object literal notation. | |
function verifyUser({ userId: id }) { | |
return User.update({ id, verified: true }); | |
} |
This file contains 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
// can destructure arrays | |
const [a, b] = [1,2]; // a = 1, b = 2 | |
// can destructure object keys | |
const { a } = { a: 3 }; // a = 3 | |
// even function parameters | |
function foo({ a }) { | |
console.log(a); | |
} |