1) Jeśli tablica w JS jest obiektem, to rozumiem, że 'this' użyte w tablicy odnosi się do tej tablicy, zgadza się?
2) No więc da się to zrobić w obrębie obiektu, czy trzeba tablicę przenieść poza obiekt?
Kod
var car = {
brand : "Mercedes",
color : "czerwony",
showText() {
console.log('hello')
}
}
var array = ['a', 'b', car.color, car.showText]
Może jeszcze podam kontekst problemu. Mam taki działający kod w projekcie:
Kod
navigationHidableReferences = (a, b, d, e, f, g) => {
nextBtn.style.display = a;
prevBtn.style.display = b;
galleryTopDiv.style.cursor = d;
thumbsDiv.style.cursor = e;
iconBar.style.display = f;
thumbnailsIconDiv.style.display = g;
};
const showWholeNavigation = [
'flex',
'flex',
'grab',
'grab',
'flex',
'flex',
navigationHidableReferences,
];
resetTimer = (a, b, d, e, f, g, navigationHidableReferencesCallback) => {
navigationHidableReferencesCallback(a, b, d, e, f, g);
clearInterval(timer);
currSeconds = 0;
timer = setInterval(startIdleTimer, 1000);
};
startIdleTimer = () => {
currSeconds += 1;
if (currSeconds === 5) {
navigationHidableReferences('none', 'none', 'none', 'none', 'none', 'none');
}
};
Kod powoduje, że po 5 sekundach braku aktywności myszy znika nawigacja. Chciałbym go uporządkować tworząc jeden obiekt. Czy taki pomysł ma w ogóle sens?