settimeout

Keep babel class as `this` when using a member function in `setTimeout`

纵然是瞬间 提交于 2019-12-24 05:47:19
问题 I have an ES2015 class, call it Foo , which has at least two member functions, bar and baz . In bar there is a call to setTimeout whose first parameter is this.baz . Works fine up to here, I inspected it in the debugger, and this does refer to the instance of my class. (Actually since I'm using babel, I end up with a _this = this substitution beforehand but anyway the right thing is being passed into the setTimeout , confirmed.) The problem is when the setTimeout callback fires, it calls the

“function is not defined” after document.write called in setTimeout?

末鹿安然 提交于 2019-12-24 05:40:30
问题 Here is the code: function getTime(j){ var stopClock= new Date(); delta[parseInt(j)]=stopClock.getMilliseconds()-start.getMilliseconds(); } //REST OF THE CODE!! function func(){ { for (var i = 0; i < 6; i++){ start = new Date(); document.write('<img src="'+URL[i]+'" width="1" height="1" alt="" onload="getTime('+i+');"/>'); } } //SOME CODE setTimeout(function() { func(); },100); However I got this error: getTime is not defined if I declare getTime like this: document.getTime= function (j)

How do I change scope of “this” in setInterval and setTimeout functions

余生长醉 提交于 2019-12-24 05:40:19
问题 How is it possible to use this inside of setInterval and setTimeout calls? I want to use it like : function myObj() { this.func = function(args) { setTimeout(function() { this.func(args); }, 1000); } } Some time ago I did it for .onclick event this way : this.click = function(func) { this.elem.onclick = (function(func, obj) {return function(){func.apply(obj)} })(func,this); }; but I don't know how I can do it for intervals and timeouts . 回答1: The easiest way is to just save this into a local.

setTimeout not delaying function call in $.each

大兔子大兔子 提交于 2019-12-24 03:26:20
问题 I several divs on my site, I'd like to update one by one. In order not to spam the server with 200+ requests at once, I'd like to delay them by 1s each. What I tried: var $tourBox = $('.tour-box'); $tourBox.each(function () { var $box = $(this); setTimeout(function () { getUpdate($box); }, 1000); }); The update function: function getUpdate($box) { var $so = $box.attr('data-so'); var $url = $('#ajax-route-object-status').val(); $.get($url, { so: $so }).success(function (data) { var $bg = 'bg

How to workaround a nodejs stable bug with setInterval/setTimeout when changing system time

泪湿孤枕 提交于 2019-12-24 03:18:25
问题 In the current stable version of node.js v0.10.33 there is a bug where setTimeout/setInterval does not fire anymore when setting the system time to the past. Run this code to see what I mean: var i = 0; var handle = setInterval(function() { console.log(++i); }, 1000); Then while it's running change the time of your system to the past, does not matter if on windows or linux. The interval / timeout will not fire anymore. When chaning the time to the future, node behaves perfectly fine and keeps

Ensure only one setTimeout runs (is active) at a time?

≯℡__Kan透↙ 提交于 2019-12-24 02:54:09
问题 The recursive setTimeout function getRandomProducts is called onload in the html body tag, and so is constantly iterating. The function setCategoryTree is being called onclick from the links in a nested ul of a navigation-bar. This function then passes the variable mainCategory to getRandomProducts, in which the variable is declared globally to maintain its' initialization. ...So, what I am trying to do is reset the getRandomProducts function when a link is clicked in the navigation-bar, and

Little help with JavaScript code involving setTimeout() method

假装没事ソ 提交于 2019-12-24 00:16:37
问题 I am trying to understand two things about this code: var updateFn = function(num){ return function(){ if(num == 6){ console.info("100%, all items saved!") } else{ var i = num/6; var pct = Math.round(100 * i); console.info(pct + "% saved"); } }; }; for (var i = 1; i < 7; i++){ setTimeout(updateFn(i), i * 500); } According to what i have read about setTimeout() syntax; setTimeout("javascriptstatement",milliseconds); So, why do I have to increment the milliseconds each loop till the total time

JQuery & Timer :: Updating the text of a hyperlink from a webservice

霸气de小男生 提交于 2019-12-23 16:07:15
问题 What I'm to figure out how to do is execute a webservice on a remote server to determine how many messages there are available to read and populate the text of a hyperlink with the message count. The trick is I'd like this to be fired from a timer (every 5 mins for example). Here's what I've been messing with $.ajax( {type:'Get',url:'http://foobar.com/ws',success:function(messageCount) { $('a.message').text(messageCount + ' Messages'); } }) but admittedly, am utterly clueless when it comes to

jquery的定时器setTimeout()与定时循环执行器setInterval()的区别

有些话、适合烂在心里 提交于 2019-12-23 13:08:02
一、定时循环执行器setInterval("getLoc()",5000);或者setInterval(getLoc,5000);的书写格式都是正确的。 这个方法是每过5秒就会执行getLoc()方法,从而调用ajax去后台访问数据。这里的ajax主要是去后台访问 经纬度的数据,以百度地图坐标的方式显示当前记录的位置。 $(function(){ setInterval(getLoc,5000); //getLoc(); }); function getLoc(){ $.ajax({ url: "/service/gps/selectTopGps", type : "POST", data:{}, success: function(ajaxData) { bm.clearOverlays(); lat=ajaxData[0].latitude; lon=ajaxData[0].longitude; // a++; // console.log(a); //调用百度地图 var x = lon*1/100; var y = lat*1/100; var ggPoint = new BMap.Point(x,y); bm.centerAndZoom(ggPoint, 15); bm.addControl(new BMap.NavigationControl()); /

nodeJS之进程process对象

不羁岁月 提交于 2019-12-23 12:52:38
前面的话   process对象是一个全局对象,在任何地方都能访问到它,通过这个对象提供的属性和方法,使我们可以对当前运行的程序的进程进行访问和控制。本文将详细介绍process对象 概述   process是一个全局对象,即global对象的属性,可以在任何地方直接访问到它而无需引入额外模块 console.log(process === global.process);//true console.log(process); 属性 【process.argv】   包含命令行参数的数组。第一个元素会是'node',第二个元素将是.js文件的名称,接下来的参数依次是命令行参数 console.log(process.argv);//[ 'D:\\nodejs\\node.exe', 'D:\\project\\main.js' ] 【process.execArgv】   启动进程所需的 node 命令行参数。这些参数不会在 process.argv 里出现,并且不包含 node 执行文件的名字,或者任何在名字之后的参数。这些用来生成子进程,使之拥有和父进程有相同的参数 console.log(process.execArgv); 【process.execPath】   开启当前进程的执行文件的绝对路径 console.log(process.execPath);//D: