Repository for Ideas & Research
Open Source GIS, Hydrologic Modeling, Optimization

JavaScript

1   jQuery deferreds and promises - .then() vs .done()

promise.then(function (x) { // Suppose promise returns "abc"
    console.log(x);
    return 123;
}).then(function (x){
    console.log(x);
}).then(function (x){
    console.log(x)
})

// outputs
abc
123
undefined

// versus

promise.done(function (x) { // Suppose promise returns "abc"
    console.log(x);
    return 123;
}).done(function (x){
    console.log(x);
}).done(function (x){
    console.log(x)
})

// outputs
abc
abc
abc