How to access promise value inside


(Rodrigogenio12) #1

I recently start contributing in a extension on github, and I face the follow problem, Promises, they work different that I think, my question is how can I access the value inside them or adapt them to my code.

browser.storage.local.get(function(o){
array.push(o.CF);
//o.CF have information of clock formart 12 or 24.
});

//the function extents in the core extension

var formatTime = function(date) {
var hour = date.getHours();
var minute = date.getMinutes();
var amPM = (hour > 11) ? “PM” : “AM”;
var formatClock = 24;

if(hour > 12) {
  hour -= 12;
}else if(hour === 0) {
hour = 12;
}

if (hour < 10) {
hour = “0” + hour;
}

if(minute < 10) {
minute = “0” + minute;
}

if(formatClock == 24){
hour = date.getHours();
return hour + “:” + minute;
}else{
return hour + “:” + minute + " " + amPM;
}
}

the function formartTime is called many times in the code, how can I adapt to works with my return value if my return value works only in then scope?

sorry for bad english.
Thanks for attention.


(Martin Giger) #2