class TestTwo {
constructor() {
this.logThis = logThis;
}
}
this.visibleCities = this.allCities.filter(city => this.defaultCitiesIds.includes(city.id))
.map(city => ({ ...city, check: false }));
this.visibleCities = this.allCities.reduce((result, city) => {
if (this.defaultCitiesIds.includes(city.id)) {
city.check = false;
result.push(city);
}
return result;
}, []);
const b = new B();
b.setX();
b.getX(); // 2
const c = new C();
c.setX();
c.getX(); // 2
class A {
static setX() {
A.prototype.x = 2;
}
}
A.prototype.x = 1;
class B extends A {
getX() {
console.log(this.x);
}
}
class C extends B {
getX() {
console.log(this.x);
}
}
A.setX();
const b = new B();
b.getX(); // 2
const c = new C();
c.getX(); // 2
но у меня такая же обертка создается и работает через call.
f.call('test2', 1, 2);
Подскажите, как правильно искать в данном! случае (именно forEach).
[].forEach.call(document.querySelectorAll('div.foo'), e => {
[].forEach.call(e.querySelectorAll('div.bar'), e => console.log(e));
});
export const withLatest = request => {
let last = 0;
return (...args) =>
new Promise((resolve, reject) => {
const current = ++last;
request(...args)
.then(res => resolve({ isLatest: current === last, res }))
.catch(err => reject({ isLatest: current === last, err }));
});
};
export const withLatest = request => {
let last = 0;
return async (...params) => {
const current = ++last;
try {
const res = await request(...params);
return { isLatest: current === last, res };
} catch (err) {
throw { isLatest: current === last, err };
}
};
};
import Api from '../api';
import { withLatest } from '../utils';
const withLatestFetchData = withLatest(Api.fetchData);
export const fetchData = query => async (dispatch, state) => {
dispatch({ type: "LOADING_DATA" });
try {
const { isLatest, res } = await withLatestFetchData(query);
if (isLatest) {
dispatch({ type: "DATA_SUCCESS", payload: res });
}
} catch ({ isLatest, err }) {
if (isLatest) {
console.log(err);
}
}
};
async function my_function() {
console.log('1');
await new Promise(resolve => {
setTimeout(() => {
console.log('2');
resolve();
}, 1000);
});
console.log('3');
}
function setAsyncTimeout(cb, timeout) {
return new Promise(resolve => {
setTimeout(() => {
cb();
resolve();
}, timeout);
});
}
async function my_function() {
console.log('1');
await setAsyncTimeout(() => { console.log('2'); }, 1000);
console.log('3');
}
немного подумав решил заменить конструкцию
Array(1000)].map(_ => <SomeComponent />);
const replies = '#react-root > div > main > div > div > div > div > div:nth-child(2)';
const goTo = async () => {
page.evaluate(replies => {
return document.querySelector(replies).children[0].innerText;
}, replies);
};
const word = 'real';
const regexp = new RegExp(`${word}\\w*`, 'ig');
string = 'really, reality, super, universe';
console.log(string.replace(regexp, 'BOOM')); // BOOM, BOOM, super, universe
const words = ['real', 'super'];
const regexp = new RegExp(`(${words.join('|')})\\w*`, 'ig');
const string = 'really, reality, super, universe';
console.log(string.replace(regexp, 'BOOM')); // BOOM, BOOM, BOOM, universe
var list = document.querySelectorAll( 'input[type=checkbox]' );
Array.prototype.forEach.call(list, function (item) {
// do something
});
@annotation
class MyClass { }
const { id } = this.state;
const { id } = this.state;
const newOrder = { id, ... };
const orders = [];
const mapLangTitleByCode = code => ({
const titles = {
1: 'English',
2: 'Russian',
};
return titles[code] || 'unknown code';
});
<div className="profile-data">
<span>Language</span>
<span>{mapLangTitleByCode(data.q_lang)}</span>
</div>
<div className="profile-data">
<span>Sex</span>
<span>{data.q_sex === 1 ? 'Male' : 'Female'}</span>
</div>