setinterval

Instantiating a class and then pass it to setInterval

*爱你&永不变心* 提交于 2019-12-11 10:36:39
问题 I've a crazy problem. I'm instantiating an object from a class. Then I want to pass a function from this object to the setInterval function. The whole code block is executed with a keyDown event. Here's the code: function doKeyDown(e){ var instance = new Class(e.keyCode); setInterval(instance.functionToBeExecuded(), 200); } The strange thing is that it's getting executed once and then starts to loop an error which states (firebug): 27 SyntaxError: missing ] after element list [object

Help chosing between settimeout and setinterval

大憨熊 提交于 2019-12-11 10:08:40
问题 UPDATE 2: OK, looks like it runs the first time after a minute. How do I get it to run onload, then every minute after that? UPDATE 1: I've tried: var interval = setInterval(get_reported_incidents, 60000); but nothing happens. in get_reported_incidents(); I just have an alert("hello"); . ORIGINAL QUESTION: I want to run a function every minute: get_reported_incidents(); But I am not sure which method is best for this task; settimeout or setinterval 回答1: It's totally personal preference.

Why is setInterval in an Angular service only firing one time?

我只是一个虾纸丫 提交于 2019-12-11 08:20:00
问题 I need to fetch updates from a server every few minutes so I'm using setInterval inside my DeliveriesService. Here is the relevant part of my deliveries.service.ts import { Injectable, OnInit } from '@angular/core'; import { Subject } from 'rxjs/Subject'; import { Http } from '@angular/http'; import { Delivery, Product } from './delivery'; @Injectable() export class DeliveriesService implements OnInit { private fetchUrl = 'https://my.url'; private getInt; public deliveries$ = new Subject

Why does setTimeout require anonymous function to work?

时光毁灭记忆、已成空白 提交于 2019-12-11 08:05:46
问题 I was reading an answer on StackOverflow here that explained how to use setTimeout to create a sort of recurring loop on a webpage. However, I am wondering why setTimeout requires an anonymous function to work. Consider the following code: trainingTimer(60,0); function trainingTimer(duration,c) { document.getElementById("timer").innerHTML = "Time left: "+(duration-c); if(duration==c) { alert("Time is up!"); } else { window.setTimeout(trainingTimer(duration,c+1),1000); } } I wrote this based

angular 2 Implement rxjs - IntervalObservable for http call for every a defined interval e.g, 5 secs

六月ゝ 毕业季﹏ 提交于 2019-12-11 07:04:11
问题 I want make a HTTP request and dynamically update in the UI the value that's being observed! import { IntervalObservable } from 'rxjs/observable/IntervalObservable'; @Component({ ... }) export class AppComponent { n: number = 0; constructor() { IntervalObservable.create(1000).subscribe(n => this.n = n); } } Is there a better way to do this? 来源: https://stackoverflow.com/questions/45263894/angular-2-implement-rxjs-intervalobservable-for-http-call-for-every-a-defined

How to call a generator (async) function on an interval basis

吃可爱长大的小学妹 提交于 2019-12-11 06:09:14
问题 I am building an app that must poll remote devices (generator fn sendRequests() ) every 2 seconds. What's the right way to call the generator fn using setInterval, which isn't a generator and doesn't yield function * sendRequests() { // multiple remote async requests are sent } var timer = setInterval(() => { // yield sendRequests() }, 2000) 回答1: Since AdonisJS uses co() under the hood, I used @Bergi suggestion of wrapping in co() function * sendRequests() { // multiple remote async requests

stopping dynamically generated setInterval

て烟熏妆下的殇ゞ 提交于 2019-12-11 04:35:53
问题 I am generating multiple charts each with their own setInterval to refresh the data. I have it set to clearInterval when the dynamically generated container is removed - but if I reload and it has the same id the old setInterval continues to run. Is there a way to set a dynamically named setInterval that can be stopped when the replacement is generated? Right now I'm using: function generateChart(data, location){ var chart = new Highcharts.Chart({ // blah blah blah }, function(chart){

Refreshing a setInterval in React

▼魔方 西西 提交于 2019-12-11 04:28:32
问题 This is based on the answer given here: I'm having trouble resetting a setInterval. As of now the following works. I have a prop called mediaList which contains an object array of images. When changeActiveMedia is called, the object position is moved to the next one in the list. class MyComponent extends React.Component { constructor(props) { super(props); this.state = { activeMediaIndex: 0 }; } componentDidMount() { setInterval(this.changeActiveMedia.bind(this), 5000); } changeActiveMedia()

Javascript setinterval() lag in Firefox?

故事扮演 提交于 2019-12-11 04:12:21
问题 I have wrote this code to make seconds (with decisec & centisec) counting up. You've wasted time <span id="alltime">0.00</span> seconds. <script type="text/javascript"> function zeroPad(num,count) { var numZeropad = num + ''; while(numZeropad.length < count) { numZeropad = "0" + numZeropad; } return numZeropad; } function counttwo() { tall = document.getElementById('alltime').innerHTML; if(parseFloat(tall) < 1.00) { tnew2 = tall.replace('0.0','').replace('0.',''); } else { tnew2 = tall

I can't get setInterval() to work in Javascript

可紊 提交于 2019-12-11 04:06:43
问题 i have an algorithm that generates permutations of a given word. I'm trying to use setInterval() to generate the next permutation but the function runs only once! I can't figure out why. I don't get any error messages. Here is my code var splitted; var t; $(document).ready(function() { $('#SubmitBtn').click(function() { //change Start to Stop and change button id $('#SubmitBtn').attr('id','StopBtn').attr('value','Stop'); //and add click event to it $('#StopBtn').click(function() {