Javascript examples for Object:Object Property
asynchronously define javascript object property using Promise
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){//from w w w. j a va 2 s. c o m function returnName() { return new Promise(function(resolve, reject) { setTimeout(function() { return resolve('John Wick'); }, 3000); }); } let person = { age: 23 }; returnName().then(function(name) { person.name = name; console.log(person); }); } </script> </head> <body> </body> </html>