有没有快速的方法让Chrome在console.log写入中输出时间戳(比如Firefox).或者是预先new Date().getTime()唯一的选择?
如果您在chrome控制台中运行它:
console.log.apply(null, [array])
Run Code Online (Sandbox Code Playgroud)
Chrome会给您一个错误:
// TypeError: Illegal Invocation
Run Code Online (Sandbox Code Playgroud)
为什么?(通过OSX在Chrome 15上测试过)
例如,如果我这样做:
var q = document.querySelectorAll;
q('body');
Run Code Online (Sandbox Code Playgroud)
我在Chrome中收到"非法调用"错误.我想不出为什么这是必要的任何理由.首先,并非所有本机代码功能都是如此.事实上我可以做到这一点:
var o = Object; // which is a native code function
var x = new o();
Run Code Online (Sandbox Code Playgroud)
一切正常.特别是在处理文档和控制台时我发现了这个问题.有什么想法吗?
我在 Javascript ES6 中有这个代码:
// Create a new object
var foo = new A();
// Create shortcuts to use localStorage faster
foo.set = window.localStorage.setItem;
foo.get = window.localStorage.getItem;
// Try to use localStorage
foo.set('count', 1);
Run Code Online (Sandbox Code Playgroud)
但是最后一行我得到了“非法调用”,我不明白为什么。
知道如何解决这个问题吗?
以下是导致错误(FF,Chrome和?):
Engine.prototype.requestAnimationFrame = window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(/* function */ callback, /* DOMElement */ element){
window.setTimeout(callback, 1000 / 60);
};
Run Code Online (Sandbox Code Playgroud)
完整的背景是:
var Engine = function(model) {
this.model = model;
};
Engine.prototype.start = function() {
console.log("ready")
this.requestAnimationFrame(function() {
console.log("done");
});
};
Engine.prototype.updateUi = function() {
console.log("update ui");
this.requestAnimationFrame(this.updateUi);
};
Engine.prototype.logRAF = function() {
console.log(window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame);
return this;
};
Engine.prototype.requestAnimationFrame = window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame …Run Code Online (Sandbox Code Playgroud) 为什么以下代码不起作用?
var f = document.getElementsByTagName;
var x = f('div');
Run Code Online (Sandbox Code Playgroud)
我在Chrome中遇到"TypeError:Illegal invocation",Safari中出现"TypeError:Type error".我没有在Firefox中收到错误,但它不起作用.我还没有在IE或Opera中进行测试.