我想要一个用JavaScript编写的严肃版的DebugOut。这是我想出来的:
function debugOut(ctlstring)
{ // debugOut
var pieces = ctlstring.split("%");
var s = pieces[0];
for (var iarg = 1; iarg < arguments.length; ++iarg)
{
s += arguments[iarg];
if (iarg < pieces.length)
s += pieces[iarg];
}
console.log(s);
} // debugOut
. . .
// E.g.:
debugOut("% was % % of the time", "Killroy", "here", 0.42);
有没有人能推荐一种更经济或更优雅的方式?
发布于 2018-10-06 21:46:32
试试这个:
function debugOut(ctlstring, ...params) {
for(var arg of params) {
ctlstring = ctlstring.replace('%', arg);
}
console.log(ctlstring);
}
// E.g.:
debugOut("% was % % of the time", "Killroy", "here", 0.42);
发布于 2018-10-07 01:29:26
凉爽的!那么,SO的代码审查部分在哪里呢?
https://stackoverflow.com/questions/52679471
复制相似问题