Console.timer() 中不存在 myTimer [英] myTimer dose not exist in Console.timer()
问题描述
我已经为 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);});
如何解决这个问题?
一旦您使用 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 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屋!