How to obtain value [[Promisevalue]]?

Asked

Viewed 1,588 times

6

I’m having trouble getting value [[PromiseValue]]

Below is an example of the image in Debugger mode:

inserir a descrição da imagem aqui

Follows code:

Html:

<img id="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" stays within the variable result.

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

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

I’m using plugin : https://foliotek.github.io/Croppie/

1 answer

8


Its variable is a Promise, that is, a promise that a certain value (the one you want to pick up) may be available in the future. When you are, that is, when the promise is settled, it executes the callbacks that have been registered before with the method then(), and passes the obtained value to those callbacks.

In your code, it 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 on the console, with double brackets [[ ... ]], is an internal property of the object, not accessible by language, only by its host (browser, nodejs, etc). This is the notation that the specification the language uses to refer to internal properties/methods/values, which only exist for the purpose of explaining how the language should work and be implemented.

  • In the variable valor returns like this: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAYAAACtWK6eAAAgAElEQV... end of the line with 3 dots. How can I get it complete ?

  • 1

    If the server is sending it complete, it should just be the console abbreviating. Your code should have access to the full value.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.