A deeper look at event loop (micro/macro tasks)

One common question So why the result is 1,2,3,5,4 rather than 1,2,3,4,5? If we look at the detail, looks like the async of setTimeout is different from the async of Promise.then, at least they are not in the same async queue. The answer is here in the whatwg SPEC. An event loop has one or more task queues.(task…

that=this in javascript

Watch Out: Callbacks And Closures Sometimes Do Not Play Nicely  Of course there are always gotchas with JavaScript. Lets define a callback function: 1 2 3 4 5 6 7 8 9 10 11 var createCallBack = function() { //First function return new function() { //Second function this.message = “Hello World”; return function() {…

javascript callback with browser dom

prototype is the function template when new is called so that it could be assign to the object’s __proto__. very good video explaining event loop/callback and browswer. Some summary: Typical type of event: User event, XHR event, Timer event. the whole picture is callstack+eventloop+web api. call stack is where the code runs eventloop is where…

understanding and using jsonp

JSONP is really a simple trick to overcome the XMLHttpRequest same domain policy. (As you know one cannot send AJAX (XMLHttpRequest) request to a different domain.) So – instead of using XMLHttpRequest we have to use script HTML tags, the ones you usually use to load js files, in order for js to get data…

javascrip callback

How Callback Functions Work? Because functions are first-class objects in JavaScript, we can treat functions like objects, so we can pass functions around like variables and return them in functions and use them in other functions. When we pass a callback function as an argument to another function, we are only passing the function definition….

async callback in GWT

The Asynchronous Interface The asynchronous interface is the one that your client-side code will use. Your code will call the service but not wait for a reply (hence the ‘asynchronous’ of course). The reply will go somewhere else. That ‘somewhere else’ is a method in the client-side code and you have to tell the gizmo…