error syntax when using then((result) =>

Asked

Viewed 81 times

0

I have a site that uses pay.me (Getaway payment) I created a webview that runs perfectly in versions android 7 and 8, but in versions 6, 5 and 4 the webview has error in javascript due to the syntax "then(result) =>" or more specific "=>" as in the code below, there is some other option?

Android Studio message: I/Chromium: [INFO:CONSOLE(244)] "Uncaught Syntaxerror: Unexpected token =>", source: http://........

pagarme.client.connect({ encryption_key: 'ek_test_eee777dddsss5555' })
  .then(client => client.security.encrypt(card))
  .then(card_hash => {
  • 1

    .then(function(client) { return client.security.encrypt(card) })

1 answer

-2

The sign => is a different notation for creating functions, called Arrow Function. For this specific case, just replace the code in order to do the functions in the traditional way, ie:

That:

parametro => {...} // arrow function

Turn that over:

function(parametro) { return ...} // função tradicional

Remembering the following: the arrow-shaped functions do not require the Return, already the traditional functions need, so you will have to add this too.

Note: There are considerations about the difference between the arrow functions and the traditional functions, but I do not have enough knowledge to list all, so I leave the link below to discuss these differences. For your problem in question the solution proposed is valid.

What the operator means "=>"?

  • 1

    Although the solution is, in fact, to change the Arrow Function for Function, I believe you have chosen the wrong words. A Arrow Function it’s not exactly just one sugar syntax for functions, there are considerations to be made mainly to the object this, as discussed in this answer.

  • 1

    @Andersoncarloswoss I understand. Thank you for the clarification, and I apologize for the lack of knowledge. I wanted to give a full reply without full knowledge of the subject.

  • In this specific case, the codes could be considered "equivalent" and the relationship would be direct (since the this within the function), then the answer is not completely wrong; I would only recommend editing and correcting the terms :D

  • I edited, I hope you’re better. Again sorry for the inexperience, I’m still learning, both in programming and in the OS.

  • There’s no need to apologize, we’re all here to learn.

Browser other questions tagged

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