Viewing Objects In Javascript ( Under The Hood )
Im very curious as to how objects are displayed in nodejs and in this case promises. When using console.log(promiseObject) the output is of type {state:pending} This seems very wei
Solution 1:
Use a debugger, your browser has probably a good one. F12 in your browser and click the Run button below and you can explore a Promise object (works in Chrome/Chromium, Edge, Firefox):
console.clear();
var a = newPromise(function(res, rej) { res(); });
console.dir(a);
then()
, catch()
and other functions are in the __proto__
property.
Solution 2:
var p1 = a()
console.log(p1)
here p1
is calling a function which returns a promise. so when you console log that promise you will see the status of promise.
But you want the object do something like
functiona(){
var deferred = q.defer();
setTimeout(function(){
var data = {status: 'resolved', value: '3'};
deferred.resolve(data);
},4000)
return deferred.promise;
}
a().then(function (data) {
console.log(data); //prints {status: 'resolved', value: '3'}
}
hope it helped
Post a Comment for "Viewing Objects In Javascript ( Under The Hood )"