Console.timer() 中不存在 myTimer [英] myTimer dose not exist in Console.timer()

查看:29
本文介绍了Console.timer() 中不存在 myTimer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为 RxJS scan() 方法创建了一个演示,但不幸的是我的计时器不能正常工作,我收到此错误:Timer 'myTimer' does not exist

console.time('myTimer');让源 = Rx.Observable.interval(100)//间隔从 0 开始.take(4).scan((acc, val) => acc + val);source.subscribe((value) => {console.timeEnd('myTimer');console.log('in next. Value: ', value);});

这是 JSBin 中的演示.

这是我从中复制代码的来源.

如何解决这个问题?

解决方案

一旦您使用 console.timeEnd("name") 停止计时器,它在使用 chrome 时不再存在.

console.time("myTimer");for(var i=0;i<10000;i++){}console.timeEnd("myTimer");//有效console.timeEnd("myTimer");//显示错误(仅在 chrome 中)

这几乎就是你的代码在做什么.第一次 subscribe 被称为您的计时器输出自启动以来的时间量.在随后的 3 次调用中,它不起作用.

此行为特定于 Chrome,它在 IE 和火狐浏览器.

I've been created a demo for RxJS scan() method but unfortunately my timer doesn't work properly and I get this error: Timer 'myTimer' does not exist

console.time('myTimer');

let source = Rx.Observable
    .interval(100) // interval starts from 0
    .take(4)
    .scan((acc, val) => acc + val);

source.subscribe((value) => {
    console.timeEnd('myTimer');
    console.log('in next. Value: ', value);
});

Here is a demo in JSBin.

Here is a source that I Copy code from that.

How can fix that issue?

解决方案

Once you've stopped the timer with console.timeEnd("name") it no longer exists when using chrome.

console.time("myTimer");
for(var i=0;i<10000;i++){
}

console.timeEnd("myTimer"); // works
console.timeEnd("myTimer"); // displays an error (in chrome only)

Which is pretty much what your code is doing. The first time subscribe is called your timer outputs the amount of time since it ws started. On the 3 subsequent calls it does not work.

This behaviour is specific to Chrome, it works how you expect in both IE & Firefox.

这篇关于Console.timer() 中不存在 myTimer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆