showing results for - "change window prototype tabclose so that it removes the correct tab "
Stefania
07 Aug 2020
1// tabs is an array of titles of each site open within the window
2var Window = function(tabs) {
3  this.tabs = tabs; // We keep a record of the array inside the object
4};
5
6// When you join two windows into one window
7Window.prototype.join = function (otherWindow) {
8  this.tabs = this.tabs.concat(otherWindow.tabs);
9  return this;
10};
11
12// When you open a new tab at the end
13Window.prototype.tabOpen = function (tab) {
14  this.tabs.push('new tab'); // Let's open a new tab for now
15  return this;
16};
17
18// When you close a tab
19Window.prototype.tabClose = function (index) {
20  var tabsBeforeIndex = this.tabs.slice(0, index); // Get the tabs before the tab
21  var tabsAfterIndex = this.tabs.slice(index + 1); // Get the tabs after the tab
22
23  this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together
24  return this;
25 };
26
27// Let's create three browser windows
28var workWindow = new Window(['GMail', 'Inbox', 'Work mail', 'Docs', 'freeCodeCamp']); // Your mailbox, drive, and other work sites
29var socialWindow = new Window(['FB', 'Gitter', 'Reddit', 'Twitter', 'Medium']); // Social sites
30var videoWindow = new Window(['Netflix', 'YouTube', 'Vimeo', 'Vine']); //  Entertainment sites
31
32// Now perform the tab opening, closing, and other operations
33var finalTabs = socialWindow
34  .tabOpen() // Open a new tab for cat memes
35  .join(videoWindow.tabClose(2)) // Close third tab in video window, and join
36  .join(workWindow.tabClose(1).tabOpen());