Q: Dojo - Json REST call in custom module contructor I'm writing a custom module in dojo 1.9 and I have this piece of code used to declare it:
define(["dojo/_base/declare", "dojo/store/JsonRest"], function(declare, JsonRest){
    return declare(null, {
        user: 'Not set',
        constructor: function(id){
            var store = new JsonRest({
                target: "myurl"
            });
            store.get('user').then(function(item){
                console.log(item.user);
                this.user = item.user;
            });
        },
        getUser: function(){
            return this.user;
        }
    });
});
In another file I use this code:
require(["modules/demo/demo"], function(demo){
        var x = new demo('7');
        alert(x.getUser());


    });

I understood my problem: getUser() function is called before the json/rest call has finished so this function
alert(x.getUser());
always return "Not set" because json value is still not loaded. How can I make getUser function wait for it?
p.s.: I'm am sure that json rest request works well because the console log is ok...
Thanks in advance

A: Such is the nature of Ajax :)
One way to do it, is to make use of the dojo/Deferred object returned by store.get().
define([
    "dojo/_base/declare", 
    "dojo/_base/lang", 
    "dojo/store/JsonRest"
], function(
    declare, 
    lang, 
    JsonRest
){
    return declare(null, {
        user: 'Not set',
        _initialized: null,
        constructor: function(id){
            var store = new JsonRest({
                target: "myurl"
            });
            this._initialized = store.get('user');

            this._initialized.then(lang.hitch(this, function(item){
                console.log(item.user);
                this.user = item.user;
            }));
        },
        initialize: function() {
            return this._initialized;
        },
        getUser: function(){
            return this.user;
        }
    });
});
....

require(["modules/demo/demo"], function(demo){
    var x = new demo('7');
    x.initialize().then(function() {
        alert(x.getUser());
    });
});

Example: http://fiddle.jshell.net/6mgwh/
