Q:

How to use Tridion JavaScript Framework (Anguilla) to wait for all the component information

How do I resolve the issue of the browser being asynchronous and each new event being added to the event stack?
In my previous question it was suggested that, because of caching, I should wait until the full component. Also this answer was giving to Robert in another topic, see below.

How do I check if a Component is the parent or a copy of the parent using the Tridion JavaScript Framework (Anguilla).
How to use Tridion JavaScript Framework (Anguilla) to get the workflowInfo for a Component?

My current code looks like this now; 
/// <summary>
///
/// </summary>
/// <returns>boolean</returns>
Extensions.Unlocalize.prototype.isEnabled = function Unlocalize$isEnabled(selection) {
    var item = $models.getItem(selection.getItem(0)),
        itemTCM = item.getId(),
        pubTCM = null,
        isAvailable = false,
        itemRegex = /.?tcm:(.*?)\-/,
        pubRegex = /.*?\-(.*)-.*/;

    console.log("Extensions.Unlocalize.prototype.isEnabled; Started."); 
    console.log("Info of parameter item at start: ", item.getInfo());     

    //Make sure the component is loaded before using getOwningPublicationId();
    var onItemLoaded = function Extensions$Unlocalize$_onItemLoaded() {
        console.log("Extensions$Unlocalize$_isEnabled; Started."); 
        $evt.removeEventHandler(item, "load", onItemLoaded);

        var itemInfo = item.getInfo();
        console.log("Info of parameter item in eventHandler: ", itemInfo);

        pubTCM = item.getOwningPublicationId(); 
        pubTCM = pubTCM.match(pubRegex);
        itemTCM = itemTCM.match(itemRegex);

        if (itemTCM[1] == pubTCM[1]) {
            isAvailable = true;
        }        
        console.log("Extensions$Unlocalize$_isEnabled; ", isAvailable);         
    };

    console.log("Extensions.Unlocalize.prototype.isEnabled; addEventHandler"); 
    $evt.addEventHandler(item, "load", onItemLoaded);

    console.log("Extensions.Unlocalize.prototype.isEnabled; item.load()"); 
    item.load(item.isLoaded(true), $const.OpenMode.VIEW);

    console.log("Extensions.Unlocalize.prototype.isEnabled; Return."); 
    return isAvailable;
}

This works all good, the only issue is the isEnabled function is finished before _onItemLoad is done, this way return isAvailable is always false. Where I would like to check if the component is in the same publication created as being selected.
The outcome of the console looks like this:
Extensions.Unlocalize.prototype.isEnabled; Started. 
Info of parameter item at start: Tridion.ContentManager.ItemInfo {ID: "tcm:24-88", Title: undefined, Icon: "T16L0P0", ItemType: "tcm:16", ItemTypeName: "Component"…}
Extensions.Unlocalize.prototype.isEnabled; addEventHandler 
Extensions.Unlocalize.prototype.isEnabled; item.load() 
Extensions.Unlocalize.prototype.isEnabled; Return. 
Extensions$Unlocalize$_isEnabled; Started.
Info of parameter item in eventHandler: Tridion.ContentManager.ItemInfo {ID: "tcm:24-88", Title: "Pie dessert wypas", Icon: "T16L0P0", ItemType: "tcm:16", ItemTypeName: "Component"…}
Extensions$Unlocalize$_isEnabled;  false 

This is of a component that is not selected in the publication it was created. If I select a component that is created in this publication the last log will be true.
How do I resolve the issue that the item is always disabled(false) in my menu. 

A:

The methods _isEnable or _isAvailable are not good places to start loading an item asynchronously it is the same for every method that will return a result because in an asynchronous execution model we cannot have a sequential execution.
SOLUTION:
_isAvailable and _isEnable are always called after you change a selection in the CMS, for instance when you select a new item in a List or in a Tree the CME will call toolbar.updateState(selection). This method will call _isAvailable and _isEnable for all the commands available including yours.
OK, how you can execute some custom logic when you select a new item in a List or in a Tree, well there are few options there, you can use a domain level javascript or my preferred way you can extend a resources group and bind a change event to the current list object or tree control, in that custom change event handler that should be executed at the end you can load your current selected item and then call toolbar.updateState(selection) once your item is already loaded, it will call your _isEnable and _isAvailable methods but your item will be already loaded so you will get access to all the information.
If you are looking for a sample about how to extend a resources group, check it out Extend a resources group
I hope this helps.
UPDATE
I have written a post about this issue with an implementation of this answer.
Full Load an Item before _isAvailable and _isEnabled are executed

