Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#14690 closed enhancement (fixed)

AMD counterpart for

Reported by: vvoovv Owned by: Rawld Gill
Priority: low Milestone: 1.8
Component: Documentation Version: 1.7.1
Keywords: Cc: Bryan Forbes
Blocked By: Blocking:

Description hasn't been updated to reflect AMD syntax.

Should .global be accessed from dojo/_base/kernel or from dojo/_base/window ?

Change History (7)

comment:1 Changed 7 years ago by bill

Owner: set to Rawld Gill
Status: newassigned

I get confused by this too. IIRC Rawld said that at least sometimes global should be accessed from kernel, for code that's supposed to work in a server environment where there is no window. But in that case, what's the meaning of anyway? (I found that manual page to be lacking.)

comment:2 Changed 7 years ago by Rawld Gill

Milestone: tbd1.8
Priority: undecidedlow
Type: defectenhancement

On the browser, is really only useful/interesting when used with the dojo/_base/window API because you can otherwise just write window.

On some other environments, the only way to reliably get to the global object without using some special variable (e.g., node's it so call a function without context like this:

  var global = (function(){return this;})();
  // global is now guaranteed to be the global object

dojo/_base/kernel initializes as such, so could be useful syntax sugar for programs that work in several different non-browser environments.

comment:3 Changed 7 years ago by bill

I guess @rcgill is saying that when running in NodeJS you should use dojo/kernel::global, but in a browser you should use dojo/_base/window::global.

BTW, ideally this would be documented in the reference pages for those modules,, which doesn't exist yet :-(, and In addition to being cross referenced from

comment:4 Changed 7 years ago by Rawld Gill

looking at this again I noticed

  • dojo/_base/kernel returns dojo
  • dojo/_base/window returns *at the time the factory is run*...which is useless with using the rest dojo/_base/window API

So, the answer is: use dojo/_base/ (or just

Leaving open to update docs.

comment:5 Changed 7 years ago by bill

Resolution: fixed
Status: assignedclosed

I updated the docs a few weeks ago, closing this.

comment:6 Changed 7 years ago by bill

Cc: Bryan Forbes added

Rawld, this is from Bryan's email, can you confirm?

In the AMD world, |this| within a factory function should always be the global object (someone please correct me if I'm wrong):

define([], function(){
   var global = this;

That seems simpler than adding dojo/_base/kernel to your dependency list.

Now, is special because it's value can be altered by dojo/_base/window::setContext() and winGlobal(), or by someone just setting = foo... but for server-ish code that feature (or side effect) doesn't seem useful, do you agree? As an example see dojo/string.js which defines substitute() as:

string.substitute = function(   /*String*/              template,
        /*Function?*/   transform,
        /*Object?*/             thisObject){
thisObject = thisObject ||;
Note: See TracTickets for help on using tickets.