How to get value [[PromiseValue]]?

2

I'm having difficulty getting value [[PromiseValue]]

Here is an example of the image in debugger mode:

Followthecodebelow:

Html:

<imgid="new_profile_photo" alt="Perfil">

JS:

$('#new_profile_photo').croppie({
    url: e.target.result,
    viewport: {
        width: 200,
        height: 200,
        type: 'circle'
    },
    boundary: {
        width: 300,
        height: 300
    }
});
var result = $('#new_profile_photo').croppie('result');

"Promisse" is within the result variable.

Does anyone have an idea how I can get the value?

Example: "data:image/png...." .

I'm using plugin: link

    
asked by anonymous 31.08.2017 / 03:13

1 answer

4

Your variable is a Promise , that is, a promise that a certain value (the one you want to get) may be available in the future. When it is, when the promise is resolved , it executes the callbacks that were previously registered with the then() method, and passes the obtained value to those callbacks.

In your code, this would look like this:

var result = $('#new_profile_photo').croppie('result');
result.then(function(valor) {
    // Faça algo com o valor aqui dentro.
    // Se precisar dele em outro lugar, chame uma função
    // e passe adiante. Não tente atribuir seu valor a uma
    // variável de fora e acessar lá embaixo, não vai funcionar.
    // (exceto em certos casos com frameworks reativos)
});

What you saw in the console, with double brackets [[ ... ]] , is an internal property of the object, not accessible by the language, only by its host (browser, nodejs, etc). This is the notation the specification of the language used to refer to properties / methods / internal values that only exist to explain how the language should work and be implemented.

    
31.08.2017 / 04:06