How to explain callbacks in plain english? How are they different from calling one function from another function?

I am going to try to keep this dead simple. A “callback” is any function that is called by another function which takes the first function as a parameter. A lot of the time, a “callback” is a function that is called when something happens. That something can be called an “event” in programmer-speak. Imagine … Read more

Callback functions in C++

Note: Most of the answers cover function pointers which is one possibility to achieve “callback” logic in C++, but as of today not the most favourable one I think. What are callbacks(?) and why to use them(!) A callback is a callable (see further down) accepted by a class or function, used to customize the … Read more

Difference between array_map, array_walk and array_filter

Changing Values: array_map cannot change the values inside input array(s) while array_walk can; in particular, array_map never changes its arguments. Array Keys Access: array_map cannot operate with the array keys, array_walk can. Return Value: array_map returns a new array, array_walk only returns true. Hence, if you don’t want to create an array as a result … Read more

How to return value from an asynchronous callback function? [duplicate]

This is impossible as you cannot return from an asynchronous call inside a synchronous method. In this case you need to pass a callback to foo that will receive the return value function foo(address, fn){ geocoder.geocode( { ‘address’: address}, function(results, status) { fn(results[0].geometry.location); }); } foo(“address”, function(location){ alert(location); // this is where you get the … Read more

How do I create delegates in Objective-C?

An Objective-C delegate is an object that has been assigned to the delegate property another object. To create one, you define a class that implements the delegate methods you’re interested in, and mark that class as implementing the delegate protocol. For example, suppose you have a UIWebView. If you’d like to implement its delegate’s webViewDidStartLoad: … Read more

How do I convert an existing callback API to promises?

Promises have state, they start as pending and can settle to: fulfilled meaning that the computation completed successfully. rejected meaning that the computation failed. Promise returning functions should never throw, they should return rejections instead. Throwing from a promise returning function will force you to use both a } catch { and a .catch. People … Read more

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

setTimeout(function() { postinsql(topicId); }, 4000) You need to feed an anonymous function as a parameter instead of a string, the latter method shouldn’t even work per the ECMAScript specification but browsers are just lenient. This is the proper solution, don’t ever rely on passing a string as a ‘function’ when using setTimeout() or setInterval(), it’s … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)