-3

Simple example

    console.log(this);
    new Ext.Promise(function(resolve, reject){
        resolve(123);
    }).then(
        function(v){
            console.log(v);
            console.log(this);
        },
        function(){},
        function(){},
        this
    );

Result is:

constructor {compDomain: constructor, type: "patient", eventbus: constructor, $observableInitialized: true, hasListeners: HasListeners…}
123
Window {speechSynthesis: SpeechSynthesis, caches: CacheStorage, localStorage: Storage, sessionStorage: Storage, webkitStorageInfo: DeprecatedStorageInfo…}

Why last parameter of the 'then' function is not working?

SamProf
  • 1,036
  • 1
  • 7
  • 8
  • 1
    What do you expect? As I see it is correct. .then() only have 2 arguments: okcallback and errorcallback. – Jorgeblom Feb 02 '17 at 11:07
  • Read the [documentation of promises.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/then). As already stated, `.then()` takes two functions as arguments. – Daniel B Feb 02 '17 at 11:45

1 Answers1

2

Ext.Promise defaults to the native implementation. To get the augmented Ext promises, you need to create an instance of Ext.Deferred:

Ext.onReady(function() {

    var deferred = new Ext.Deferred();

    setTimeout(function() {
        deferred.resolve('GO');
    }, 1000);

    var scope = {
        foo: 'bar'
    };

    Ext.Deferred.all([deferred.promise]).then(function() {
        console.log(this.foo);
    }, null, null, scope);

});
Evan Trimboli
  • 29,900
  • 6
  • 45
  • 66