dojo.provide defines a code module so that the loader sees it and creates an object from the global namespace with this name. From this point you can bind the code directly to this global variable, for example.
Change houses / test.js:
dojo.provide('module.test'); module.test.myFunc = function() { return 'found me'; }
There are various templates that you can use, for example, creating a closure and hiding implementations of "private" functions by exposing them through a global link created in dojo.provide:
dojo.provide('module.test'); function(){ // closure to keep top-level definitions out of the global scope var myString = 'found me'; function privateHelper() { return myString; } module.test.myFunc = function() { return privateHelper(); } }();
Note that the above simply puts the methods directly on the object. Now there is also dojo.declare , which is often used with dojo.provide to create an object with prototypes and mixins, so that you can create instances with the keyword "new" with some inheritance, even simulating multiple vai mixins inheritance. Such an abstraction of OO is often abused. It approximates the patterns required by languages ββsuch as Java, so some people use it to declare objects for everything.
Note that with Dojo 1.5, dojo.declare returns an object and does not have to declare anything in the global scope.
source share