Hello I'm trying to run this code in the OOP Class framework however there's this error of "Cannot read properties of undefined (reading 'join').
Why is that?
class Window {
constructor(tabs) {
this.tabs = tabs;
}
join(otherWindow) {
const {tabs} = this;
tabs = tabs.concat(otherWindow.tabs)
}
tabOpen() {
const {tabs} = this;
tabs.push('new tab')
}
tabClose(index) {
const {tabs} = this;
const tabsBeforeIndex = tabs.slice(0, index)
const tabsAfterIndex = tabs.slice(index+1)
tabs = tabsBeforeIndex.concat(tabsAfterIndex)
}
}
const workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp'])
const socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']);
const videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']);
const finalTabs = socialWindow.tabOpen().join(videoWindow.tabClose(2)).join(workWindow.tabClose(1).tabOpen());
console.log(finalTabs)
Looked at it for 3 hours and finally understood why.