const obj1 = { a : 1, b : 2 };
const obj2 = { c : 3, a : 4 };
const result = { ...obj1, ...obj2 };
const obj1 = { a : 1, b : 2 };
const obj2 = { c : 3, a : 4 };
const result = Object.assign({}, obj1, obj2);
let obj1 = { a : 1, b : 2 };
const obj2 = { c : 3, a : 4 };
obj1 = Object.assign(obj1, obj2);
при сабмите this.request(e.target) отрабатывает как нужно, но setState не срабатывает совсем.
handleSubmit = e => {
};
this.setState({
currentState: {
...this.state.currentState,
submited: true,
},
});
PS как я могу изменить состояние после возвращения request. В функции .then контекст this я получить не могу
this.request(e.target).then(() => {
this.setState({
currentState: {
...this.state.currentState,
submited: true
}
});
});
handleSubmit = async e => {
e.preventDefault();
await this.request(e.target);
this.setState({
currentState: {
...this.state.currentState,
submited: true
}
});
};
Чтобы sum(1), а также sum(1)(2) можно было вызвать новыми скобками – результатом sum должна быть функция.
Но эта функция также должна уметь превращаться в число. Для этого нужно дать ей соответствующий valueOf. А если мы хотим, чтобы и в строковом контексте она вела себя так же – то toString.
// without compose
withLog(withRouter(connect(mapStateToProps)(withDropdown(props)(Component))));
// with compose
compose(
withLog,
withRouter,
connect(mapStateToProps),
withDropdown(props),
)(Component);
const foo = compose(...functions);
mappedValue = callback.call(T, kValue, k, O);
return this.brands.map(brand => console.log(` The ${brand} is a ${this}`));
return this.brands.map(function(brand) { console.log(` The ${brand} is a ${this}`; }, this));
<script>window.__INITIAL_STATE__ = { ... }</script>
const VAT_RATES = {
FR: 20,
GB: 20,
IT: 22,
PL: 23,
};
const createWithVAT = vat => price => price + price * vat / 100;
const currentVAT = VAT_RATES.GB;
const withVAT = createWithVAT(currentVAT);
const price = 250;
const totalPrice = withVAT(price);
console.log(totalPrice); // 300
var t0 = performance.now();
doSomething();
var t1 = performance.now();
console.log("Call to doSomething took " + (t1 - t0) + " milliseconds.");
var t0, t1;
var results = [];
for (var i = 0; i < nTimes; i++) {
t0 = performance.now();
doSomething();
t1 = performance.now();
results.push(t1 - t0);
}
// если надо вывести результат
results.forEach(function(result, i) {
console.log('Call to doSomething #' + (i + 1) + ' took ' + result + ' milliseconds.');
});
const handleKeyUp = e => {
// handler
};
k.on(this.searchInput.el, 'keyup', _.debounce(handleKeyUp, 300), this);
function debounce(f, ms) {
let timer = null;
return function (...args) {
const onComplete = () => {
f.apply(this, args);
timer = null;
}
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(onComplete, ms);
};
}
table.innerHTML += `<tfoot><tr id="total-price"><td colspan="3">Total price:
${shop.totalProductsPrice}</td></tr></tfoot>`;
table.innerHTML += some;
, равносилен table.innerHTML = table.innerHTML + some;
NaN === ""
возвращает false.