I would avoid multiline var
for several reasons:
- You're visually grouping statements which may have unrelated logic except that you initialize variables. Example:
var {a, b} = getValues();
a = a || initializeA();
// good logical grouping
const filter = (array, template) => array; | |
filter([{ a: 1, c: 2 }, { a: 3, b: 4 }, { a: 3, b: 2 }], { a: 1 }); // [{ a: 1, c: 2 }] | |
filter([{ a: 1, b: 2 }, { a: 3, b: 4 }, { a: 3, b: 2 }], { a: 3 }); // [{ a: 3, b: 4 }, { a: 3, b: 2 }] | |
filter([{ a: 1, c: 2 }, { a: 3, b: 4 }, { a: 3, b: 2 }], { a: 3, c: 2 }); // [] |
const [a, setA] = useState(1); | |
if (value < 0.5) { | |
const [b, setB] = useState(2); | |
} | |
const [c, setC] = useState(3); | |
console.log(c); // ? | |
// render 1: value < 0.5 | |
// render 2: value > 0.5 |
const add = () => {}; | |
const divide = () => {}; | |
const multiply = () => {}; | |
const apply = () => {}; | |
const result = apply( | |
multiply(5), | |
add(1), | |
divide(2) |
const getRandomLight = () => Math.random() >= 0.5; | |
const generateTrain = (length) => { | |
const head = { | |
prev: null, | |
next: null, | |
light: getRandomLight() | |
}; | |
let prev = head; | |
for (let i = 0; i < length; i++) { |
const { debounce, throttle, times, delay } = require('lodash'); | |
const superContext = { | |
debounced: debounce(function () { | |
console.log(this.i); | |
}, 100), | |
throttled: throttle(function () { | |
console.log(this.i); | |
}, 100) | |
}; |
<FluxCache store={store} propName="items" component={Component} id={this.props.routeParams.id} /> | |
var FluxCache = React.createClass({ | |
componentWillMount() { | |
this.props.store.addListener('change', this.onStoreChange); | |
}, | |
componentWillUnmount() { | |
this.props.store.removeListener('change', this.onStoreChange); | |
}, | |
onStoreChange() { |
class String | |
def constantize context = nil, &block | |
const_names = self.split '::' | |
if const_names.first.empty? | |
const_names.shift | |
const = ::Object | |
else | |
const = if context | |
context.class | |
elsif block |
require 'eventmachine' | |
require 'em-http-request' | |
require 'fiber' | |
class FiberPool | |
class Fiber < ::Fiber | |
def initialize pool, *args | |
@resumed = false |