All Questions

631
votes
5answers
162896 views

How to access the correct `this` inside a callback?

I have a constructor function which registers an event handler: function MyConstructor(data, transport) { this.data = data; transport.on('data', function () { alert(this.data);...
400
votes
16answers
101216 views

How do I convert an existing callback API to promises?

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 callbac...
295
votes
3answers
196385 views

How to return value from an asynchronous callback function?

This question is asked many times in SO. But still I can't get stuff. I want to get some value from callback. Look at the script below for clarification. function foo(address){ // google map...
656
votes
18answers
295689 views

How do I create delegates in Objective-C?

I know how delegates work, and I know how I can use them. But how do I create them?
248
votes
6answers
50569 views

Aren't promises just callbacks?

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){ api...
158
votes
5answers
109182 views

Pass correct "this" context to setTimeout callback?

How do I pass context into setTimeout? I want to call this.tip.destroy() if this.options.destroyOnHide after 1000 ms. How can I do that? if (this.options.destroyOnHide) { setTimeout(function() {...
597
votes
18answers
380906 views

How can I pass a parameter to a setTimeout() callback?

I have some JavaScript code that looks like: function statechangedPostQuestion() { //alert("statechangedPostQuestion"); if (xmlhttp.readyState==4) { var topicId = xmlhttp.responseText; ...
464
votes
18answers
223374 views

What is a callback function?

What is a callback function?
19
votes
3answers
7492 views

Pass an extra argument to a callback function

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); };...
11
votes
2answers
11512 views

Why is Button parameter "command" executed when declared?

I'm new to Python and trying to write a program with tkinter. Why is the Hello-function below executed? As I understand it, the callback would only be executed when the button is pressed? I am very co...

Previous Next