我们可以创建一个函数
p
在以下代码中:
var p = function() { };
if (typeof(console) != 'undefined' && console.log) {
p = function() { console.log(arguments); };
}
但是参数像数组一样传递给
console.log
,而不是像在
console.log(arguments[0], arguments[1], arguments[2], ...
是否有方法像上面那样展开参数并传递到console.log?
请注意
如果原始代码是
var p = function() { };
if (typeof(console) != 'undefined' && console.log) {
p = console.log;
}
然后它在firefox和ie 8上运行良好,但在chrome上没有。