最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is causing 'myTimer does not exist' error in console.timeEnd()? - Stack Overflow

programmeradmin7浏览0评论

I've 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?

I've 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?

Share Improve this question edited Mar 24, 2023 at 17:52 mikemaccana 124k110 gold badges430 silver badges533 bronze badges asked May 25, 2018 at 8:10 user4661780user4661780 2
  • 2 Hi! The way SO works, your whole question (including any necessary code) has to be in your question, not just linked. Two reasons: People shouldn't have to go off-site to help you; and links rot, making the question and its answers useless to people in the future. Please put a minimal reproducible example in the question, ideally a runnable one using Stack Snippets (the [<>] toolbar button; here's how to do one). More: How do I ask a good question? – T.J. Crowder Commented May 25, 2018 at 8:12
  • 3 How does the title "Console.timer() dose not exist" relate to the error message "Timer 'myTimer' does not exist"? – T.J. Crowder Commented May 25, 2018 at 8:13
Add a ment  | 

2 Answers 2

Reset to default 5

You may be calling timeEnd() multiple times.

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.

Just add

console.time("myTimer")

at the start of your function in which you are using .timeEnd

发布评论

评论列表(0)

  1. 暂无评论