[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

callback function?! what is it?!?

Andrea

8/21/2014 2:23:00 PM

Hallo!
In line 121 at code in
https://github.com/brianreavis/selectize.js/blob/master/examples/c...

there is a function called "calback"
I can not see where it is defined. What is it? is it a javascript function?
is it a Jquery function?
what does it do?

Thank you in advance for te time you'll spend for answering me
Andrea

P.S. following there is part of the code:

$select_state = $('#select-state').selectize({
onChange: function(value) {
if (!value.length) return;
select_city.disable();
select_city.clearOptions();
select_city.load(function(callback) {
xhr && xhr.abort();
xhr = $.ajax({
url: 'http://www.....te_of/' + value + '.json',
success: function(results) {
select_city.enable();
callback(results);
},
error: function() {
callback();
}
})
});
}
});
1 Answer

JR

8/21/2014 9:40:00 PM

0

On 21/08/2014 11:22, Andrea wrote:
> Hallo!
> In line 121 at code in
> https://github.com/brianreavis/selectize.js/blob/master/examples/c...
>
> there is a function called "calback"
> I can not see where it is defined. What is it? is it a javascript function?
> is it a Jquery function?
> what does it do?
>
> Thank you in advance for te time you'll spend for answering me
> Andrea
>
> P.S. following there is part of the code:
>
> $select_state = $('#select-state').selectize({
> onChange: function(value) {
> if (!value.length) return;
> select_city.disable();
> select_city.clearOptions();
> select_city.load(function(callback) {
> xhr && xhr.abort();
> xhr = $.ajax({
> url: 'http://www.....te_of/' + value + '.json',
> success: function(results) {
> select_city.enable();
> callback(results);
> },
> error: function() {
> callback();
> }
> })
> });
> }
> });
>

A callback function, or simply a "callback", is a function passed as a
parameter to other functions, in order to execute specific tasks and /
or after certain I/O operations

E.g.

function doSomething(callback) {
var results;
// compute some results
if (typeof callback == "function") {
callback(results);
}
}

function write2Server(file) {
// this will be called back in doSomething().
}

doSomething(write2Server);

--
Joao Rodrigues