Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Promise is not a constructor

I'm trying to use a promise but get a type error: Promise is not a constructor.

Here's the promise:

        var Promise = new Promise(
            function (resolve,error) {
                for (var key in excludeValues) {
                   /* some ifs */
                    minVal = someValue 
                    ........
                    ........
                    }


                resolve(errors)
            });
            Promise.then(
            function(data){
                if (minVal > maxVal)
                {
                    errors.minMax.push(
                        'minMax'
                    )
                }

                if (gapVal > minVal * -1)
                {
                    errors.minMax.push(
                        'gapVal'
                    )
                }
                return (errors.minMax.length == 0 && errors.zahl.length == 0 && errors.hoch.length == 0 && errors.niedrig.length == 0)
            }
        );

Can someone tell me what I'm doing wrong?

like image 919
baao Avatar asked Feb 10 '23 05:02

baao


1 Answers

With var Promise you declare a local variable in your scope. It is initialised with undefined and shadows the global Promise constructor. Use a different variable name

var promise = new Promise(…);
promise.then(…);

or none at all

new Promise(…).then(…);
like image 191
Bergi Avatar answered Feb 12 '23 22:02

Bergi