I want store two variable with PopupMenu.PopupImageMenuItem object, and push them into an array, then want change the text of those popupmenuitems later every 10 seconds.
var list = new Array();
function add_timer (){
//~ return function(){
let d = parseInt(input.text);
if(isNaN(d) || d < 1){return;}
...
PopupMenu.PopupImageMenuItem.prototype.count = d;
PopupMenu.PopupImageMenuItem.prototype.left = d;
let item = new PopupMenu.PopupImageMenuItem(text, stock_icon.icon_name);
...
that.menu.addMenuItem(item);
list.push(item);
var i = item; log(i.count+' <====== '+i.left);
<======== here I got last input number is right one each time.
2 <====== 2
45 <====== 45
<=========================================
//~ }
}
//~ ---------------------------------------------------------
GLib.timeout_add_seconds(GLib.PRIORITY_DEFAULT, 10, () => {
log("======"+list.length+"======");
list.forEach((i)=>{
log(i.text +': '+ i.count+' <--- '+i.left);
<========= here I got undefined and error number. all number is last input one.
======2======
undefined: 45 <--- 45
undefined: 45 <--- 45
<======================
})
return GLib.SOURCE_CONTINUE; //true
});
It's like a closure problem, or error used prototype
? or push works error? if the item in array is undefined
, how can I get a list of PopupImageMenuItem object. My first time write js, so maybe it foolish problem. Please help.