Dev: Support multiple console log arguments

This commit is contained in:
surunzi
2016-05-03 21:50:45 +08:00
parent fac653109f
commit 2ff22c3a03
3 changed files with 29 additions and 9 deletions

View File

@@ -26,10 +26,10 @@ export default class Console extends Tool
var log = this._log, var log = this._log,
winConsole = window.console; winConsole = window.console;
winConsole.log = function (msg) { log.log(msg) }; winConsole.log = function () { log.log.apply(log, arguments) };
winConsole.error = function (msg) { log.error(msg) }; winConsole.error = function (msg) { log.error(msg) };
winConsole.info = function (msg) { log.info(msg) }; winConsole.info = function () { log.info.apply(log, arguments) };
winConsole.warn = function (msg) { log.warn(msg) }; winConsole.warn = function () { log.warn.apply(log, arguments) };
winConsole.dir = function (obj) { log.dir(obj) }; winConsole.dir = function (obj) { log.dir(obj) };
winConsole.time = function (name) { log.time(name) }; winConsole.time = function (name) { log.time(name) };
winConsole.timeEnd = function (name) { log.timeEnd(name) }; winConsole.timeEnd = function (name) { log.timeEnd(name) };

View File

@@ -50,6 +50,18 @@ function transMsg(msg)
return util.escape(msg); return util.escape(msg);
} }
function transMultipleMsg(args)
{
var ret = [];
util.each(args, function (val)
{
ret.push(transMsg(val));
});
return ret.join(' ');
}
function transCode(code) function transCode(code)
{ {
return code.replace(/\n/g, '<br/>').replace(/ /g, '&nbsp;'); return code.replace(/\n/g, '<br/>').replace(/ /g, '&nbsp;');
@@ -135,9 +147,9 @@ export default class Log extends util.Emitter
return this; return this;
} }
log(msg) log()
{ {
msg = transMsg(msg); var msg = transMultipleMsg(arguments);
this._logs.push({ this._logs.push({
type: 'log', type: 'log',
@@ -183,9 +195,9 @@ export default class Log extends util.Emitter
return this; return this;
} }
info(msg) info()
{ {
msg = transMsg(msg); var msg = transMultipleMsg(arguments);
this._logs.push({ this._logs.push({
type: 'info', type: 'info',
@@ -196,9 +208,9 @@ export default class Log extends util.Emitter
return this; return this;
} }
warn(msg) warn()
{ {
msg = transMsg(msg); var msg = transMultipleMsg(arguments);
this._logs.push({ this._logs.push({
type: 'warn', type: 'warn',

View File

@@ -19,5 +19,13 @@ export default [
util.evalCss(borderCss); util.evalCss(borderCss);
}, },
desc: 'Add color borders to all elements' desc: 'Add color borders to all elements'
},
{
name: 'Refresh Page',
fn: function ()
{
window.location.reload();
},
desc: 'Refresh current page'
} }
]; ];