如何解决如何在VS Code中获得一行而不是行的数组列表?
当我在VSCode中运行此代码时
var Window = function(tabs) {
this.tabs = tabs; // We keep a record of the array inside the object
};
// When you join two windows into one window
Window.prototype.join = function (otherWindow) {
this.tabs = this.tabs.concat(otherWindow.tabs);
return this;
};
// When you open a new tab at the end
Window.prototype.tabOpen = function (tab) {
this.tabs.push('new tab'); // Let's open a new tab for now
return this;
};
// When you close a tab
Window.prototype.tabClose = function (index) {
// Only change code below this line
var tabsBeforeIndex = this.tabs.splice( index,2); // Get the tabs before the tab
var tabsAfterIndex = this.tabs.splice(index + 1); // Get the tabs after the tab
this.tabs = tabsBeforeIndex.concat(tabsAfterIndex); // Join them together
// Only change code above this line
return this;
};
// Let's create three browser windows
var socialWindow = new Window(['FB','Gitter','Reddit','Twitter','Medium']); // Social sites
var videoWindow = new Window(['Netflix','YouTube','Vimeo','Vine']); // Entertainment sites
var workWindow = new Window(['GMail','Inbox','Work mail','Docs','freeCodeCamp']); // Your mailbox,drive,and other work sites
// Now perform the tab opening,closing,and other operations
var finalTabs = socialWindow
.tabOpen() // Open a new tab for cat memes
.join(videoWindow.tabClose(2)) // Close third tab in video window,and join
.join(workWindow.tabClose(1).tabOpen());
console.log(finalTabs.tabs);
console.log(socialWindow.tabOpen().join(videoWindow.tabClose(2)));
我的VSCode终端中的结果返回
Window {
tabs: [
'FB','Medium','new tab','Vine','freeCodeCamp','new tab'
]
}
有人知道我如何更改列吗?我想在一行中查看数组... 有可以更改此设置的设置吗?谢谢!
解决方法
您需要使用 Node.js internal API - util.inspect
:
console.log(util.inspect(socialWindow.tabOpen().join(videoWindow.tabClose(2)),{compact: true}));
或者简单地说,覆盖默认的console.log
:
const { inspect } = require('util');
let temp = console.log
console = {
...console,log: (...a) => temp(...a.map(b => inspect(b,{ compact: true,breakLength: Infinity })))
}
console.log(socialWindow.tabOpen().join(videoWindow.tabClose(2)));
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。