Enable / Disable UI elements

After many trials, I found out that the attributes / local variables can be used to enable / disable.
(this.menu.enabled = true) gives an error.

However declaring a var (globally, outside a function’s scope and not an attribute) works.
full code is below

var Uimanager = pc.createScript(‘uimanager’);

Uimanager.attributes.add(‘menuButton’, {
type:‘entity’,
title:‘Menu Button’
});

var menu;

Uimanager.prototype.initialize = function()
{
menu = this.menu;
this.menuButton.element.on(‘mousedown’, this.onMenuBtnPressed, this.menuButton);
};

Uimanager.prototype.onMenuBtnPressed = function (event)
{
menu.enabled = !isMenuOpen;
isMenuOpen = !isMenuOpen;
};