x
- свойство экземпляра, другой - статический геттер:class Base {
constructor() {
this.x = 3;
}
static get x() {
return 1.5;
}
}
function Base() {
this.x = 3;
}
Base.x = 1.5;
// или
function Base() {}
Base.prototype.x = 3;
Base.x = 1.5;
class Base {
x = 3;
static x = 1.5;
}
я открыл доселе неизвестный it-сообществу баг...
... или где-то далеко по мне плачет один учебник по js?
setInterval(this.tick, interval);
наsetInterval(this.tick.bind(this), interval);
setInterval(() => this.tick(), interval);
const ancestor = 'селектор элементов, которые надо получить';
const descendant = 'селектор вложенных элементов';
Array.prototype.filter.call(
document.querySelectorAll(ancestor),
n => n.querySelector(descendant)
)
Array.from(
document.querySelectorAll(`${ancestor} ${descendant}`),
n => n.closest(ancestor)
)
[...document.querySelectorAll(descendant)].reduce(
(acc, n) => ((n = n.closest(ancestor)) && acc.push(n), acc),
[]
)
document.querySelectorAll(`${ancestor}:has(${descendant})`)
const response = myFunction(1);
this.setState({ response });
componentDidMount() {
const { someValue } = this.props;
// асинхронный вызов, возвращающий Promise
fetchSomeData(someValue).then(response => this.setState({ response }));
}
async componentDidMount() {
const { someValue } = this.props;
// асинхронный вызов, возвращающий Promise
const response = await fetchSomeData(someValue);
this.setState({ response }));
}
const myFunction = num => ++num;
str.match(/\w+$/)[0]
str.split(/\W/).pop()
str.replace(/.*\W/, '')
-1
, с единицей это 0
, т.е., начало строки) и до конца:str.slice(1 + Math.max(...[...'@/'].map(n => str.lastIndexOf(n))))
[...str].reduce((acc, n) => '@/'.includes(n) ? '' : acc + n, '')
Стрелочные функции не создают собственный контекст this, а используют значение this окружающего контекста.© mdn