All Questions

684
votes
6answers
183292 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);...
427
votes
17answers
110156 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...
311
votes
3answers
208624 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...
663
votes
18answers
300773 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?
262
votes
6answers
57284 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...
163
votes
5answers
114231 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() {...
616
votes
18answers
394279 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; ...
486
votes
18answers
232777 views

What is a callback function?

What is a callback function?
22
votes
3answers
10207 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); };...
12
votes
2answers
12729 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