相关疑难解决方法(0)

Chrome中的console.log时间戳?

有没有快速的方法让Chrome在console.log写入中输出时间戳(比如Firefox).或者是预先new Date().getTime()唯一的选择?

javascript google-chrome

206
推荐指数
11
解决办法
12万
查看次数

TypeError:console.log.apply上的非法调用

如果您在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上测试过)

javascript console google-chrome

128
推荐指数
1
解决办法
3万
查看次数

为什么JavaScript中的某些函数调用被称为"非法调用"?

例如,如果我这样做:

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 invocation

79
推荐指数
1
解决办法
4万
查看次数

使用“快捷方式”功能会给我一个“非法调用”错误

我在 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)

但是最后一行我得到了“非法调用”,我不明白为什么。

知道如何解决这个问题吗?

javascript local-storage ecmascript-6

4
推荐指数
1
解决办法
964
查看次数

requestAnimation frame error

以下是导致错误(FF,Chrome和?):

JSFiddle娱乐

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)

javascript html5 animation requestanimationframe

2
推荐指数
1
解决办法
1217
查看次数

document.getElementsByTagName的本地副本

为什么以下代码不起作用?

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中进行测试.

javascript getelementsbyname

1
推荐指数
1
解决办法
792
查看次数