The js callback function entered by import does not return a value.

I wrote all the js about the smart contract in a js, and then called it with the js of the page. The callback function does not return a value.

Public js written by oneself
clipboard.png


index.js




localhost

clipboard.png

clipboard.png


export?


will

getuser(getuserCallBack());

Change

to

getuser(getuserCallBack);

export function getuser(getuserCallBack) {
    const result = 123456789;
    return getuserCallBack(result);
}
import {getuser} from './eosFunc';
export default function getuser(getuserCallBack) {
    const result = 123456789;
    return getuserCallBack(result);
}
import getuser from './eosFunc';

first of all, @ he's right
the reason, uh, when we look at it with type system (flow/ts), it's very clear

.
function getuser(getuserCallBack: function):any {
    const result = 123456789;
    return getuserCallBack(result);
}

function getuserCallBack(result: any):void {
    alert(result);
}

it is obvious that the parameter type accepted by the getuser method should be function, but what you fill in is getuserCallBack (), which means the execution result of the getuserCallBack function, that is, void
so, report an error


can be called after changing the original co-owned function function getuser to var getuser = function, but the public function cannot get its roomn value.

Menu