I am trying to add the property disabled: true or nothing at all conditionally depending on the value of on like that:
var on = true;
pMenu.addChild(new MenuItem({
label: "Disabled menu item",
if(on){
return disabled: true;
}
}));
This seems to return an error in the console “number is not a function”.
I guess this should work:
If
onis really meant to be aboolean-value in your usecase, you can also just assign it to to disabled likedisabled: on, thats it. But as far as i know, you can not execute statements (like anif-cascade in a non constructor object declaration like{}does.As
disabledisfalseby default, this is actually like adding nothing at all, but it becomes more readable in my personal opinion.Think about it: you don’t add a property to the instance, you actually just want to set a value to a propery that’s already there.