Por favor ayuda, quiero usar el resultado de la función 1 (Fn1) en la función 2 (Fn2).
App={ st: null,//st is number value Fn1: function() { App.contracts.contractName.deployed().then(function(instance){ return instance.getST(); }).then(function(result){ App.st = result; }); }, Fn2: function() { alert(App.st)// } }Debe llamar a Fn1 antes de Fn2 para acceder a su valor, así que Fn1 en Promise :
App = { st: null,//st is number value Fn1: function() { return new Promise((resolve, reject) => { App.contracts.contractName.deployed().then(function(instance){ return instance.getST(); }).then(function(result){ App.st = result; resolve(); }).catch(function(err){ reject(err); }) }) }, Fn2: function() { alert(App.st) } }o mejor con async/await :
App = { st: null,//st is number value Fn1: async function() { try { const instance = await App.contracts.contractName.deployed(); const result = await instance.getST(); App.st = result; } catch(err) { throw err; } }, Fn2: function() { alert(App.st) } } Ahora puede esperar hasta Fn1 exec antes de llamar a Fn2 :
App.Fn1().then(function() { App.Fn2() })o usando async/await :
await App.Fn1() App.Fn2()