From the documentation for declare:
http://puremvc.org/pages/docs/JS/native-multicore/#!/api/puremvcDeclare a namespace and optionally make an Object the referent of that namespace.console.assert(null == window.tld, 'No tld namespace');
// declare the tld namespace
puremvc.declare('tld');
console.assert('object' === typeof tld, 'The tld namespace was declared');
// the method returns a reference to last namespace node in a created hierarchy
var reference= puremvc.declare('tld.domain.app');
console.assert(reference === tld.domain.app)
// of course you can also declare your own objects as well
var AppConstants=
{
APP_NAME: 'tld.domain.app.App'
};
puremvc.declare('tld.domain.app.AppConstants', AppConstants);
console.assert(AppConstants === tld.domain.app.AppConstants,
'AppConstants was exported to the namespace');
Note that you can also declare within a closure. That way you can selectively export Objects to your own namespaces without leaking variables into the global scope.(function(){
// this var is not accessible outside of this
// closures call scope
var hiddenValue= 'defaultValue';
// export an object that references the hidden
// variable and which can mutate it
puremvc.declare
(
'tld.domain.app.backdoor'
, {
setValue: function (value)
{
// assigns to the hidden var
hiddenValue= value;
}
, getValue: function ()
{
// reads from the hidden var
return hiddenValue;
}
}
);
})();
// indirectly retrieve the hidden variables value
console.assert('defaultValue' === tld.domain.app.backdoor.getValue());
// indirectly set the hidden variables value
tld.domain.app.backdoor.setValue('newValue');
// the hidden var was mutated
console.assert('newValue' === tld.domain.app.backdoor.getValue());
On occasion, primarily during testing, you may want to use declare, but not have the global object be the namespace root. In these cases you can supply the optional third scope argument.var localScope= {}
, object= {}
puremvc.declare('mock.object', object, localScope);
console.assert(null == window.mock, 'mock namespace is not in global scope');
console.assert(object === localScope.mock.object, 'mock.object is available in localScope');
Hope this helps,
-=Cliff>