Question is quite simple, in this code here
class Identifier {
    constructor(id) {
        if (/^[0-9]*$/.test(id)) {
            database.exists('users', {userid: id}).then(exists => {
                if (exists) {
                    this.id = id;
                } else {
                    throw 'id_not_exist';
                }
            });
        }
    }
}
I'm trying to set a property of the class as the result of a callback function. However, when executing this code
var ident = new Identifier(1);
console.log(ident.id);
The value returned is undefined, which seems to indicate the constructor function finishes before the callback is executed. Shouldn't the constructor block until the callback is complete? Is there a better way to do this?
 
    