I have a constructor function which registers an event handler: function MyConstructor(data, transport) { this.data = data; transport.on('data', function () { alert(this.data); }); } // Mock transport object var tran...
I want to work with promises but I have a callback API in a format like: 1. DOM load or other one time event: window.onload; // set to callback ... window.onload = function() { }; 2. Plain callback: function request(onChangeHandler) { ......
I've been developing JavaScript for a few years and I don't understand the fuss about promises at all. It seems like all I do is change: api(function(result){ api2(function(result2){ api3(function(result3){ // do...
I have a function callWithMagic which takes a callback function as a parameter and calls it with one argument. const callWithMagic = callback => { const magic = getMagic(); callback(magic); }; I also have a function processMagic which tak...
I want to know when an image has finished loading. Is there a way to do it with a callback? If not, is there a way to do it at all?...
I have this counter I made but I want it to run forever, it's really simple, what am I doing wrong here? function timer() { console.log("timer!") } window.setInterval(timer(), 1000)...
I'm trying to pass some parameter to a function used as callback, how can I do that? function tryMe (param1, param2) { alert (param1 + " and " + param2); } function callbackTester (callback, param1, param2) { callback (param1,...
As the title suggests. How do I do this? I want to call whenAllDone() after the forEach-loop has gone through each element and done some asynchronous processing. [1, 2, 3].forEach( function(item, index, array, done) { asyncFunction(item,...
I understand passing in a function to another function as a callback and having it execute, but I'm not understanding the best implementation to do that. I'm looking for a very basic example, like this: var myCallBackExample = { myFirs...
I have a simplified function that looks like this: function(query) { myApi.exec('SomeCommand', function(response) { return response; }); } Basically i want it to call myApi.exec, and return the response that is given in the callb...
©2020 All rights reserved.