AMD proposal change: define.amd

8 views
Skip to first unread message

James Burke

unread,
Jan 5, 2011, 2:52:46 PM1/5/11
to comm...@googlegroups.com
I would like to make the following change to the AMD proposal:

This came up in the discussion of jQuery registering as a module.
There is concern that just testing for the presence of define as a
function is not a strong enough test to register as a module. There
could be preexisting define() in the page that is not the AMD define.
Recall in script src loading, AMD define needs to be a global.

So I would like to add the following:

There is an "amd" property on the define function that indicates it
participates in AMD, and the value is an object.

Property values on the amd object that start with "version" are
reserved for indicating which versions of AMD the implementation
supports.

Other properties would be allowed on the object to indicate other
features supported by the AMD implementation. So for RequireJS, it
would look like

define.amd = {
"version1": true,
"noConflict": true
};

For jQuery in particular, the noConflict support is important since
they provide a "noConflict" option today, and they want to maintain
that approach for define calls -- more than one jQuery can end up in
the page due to third party scripts in pages, and they want a way to
make sure that will still work. So the jquery test would test that the
amd property exists and that version1 and noConflict was true.

In RequireJS the noConflict capability is provided by "contexts" so
RequireJS can set noConflict to true. Other AMD implementors could set
noConflict to true if they provided some other mechanism to allow
multiple versions of a module could be loaded in the page.

Why version1 properties instead of a version field? It should be easy
test for module authors to use, and I can see implementations
supporting multiple versions. It also allows finer grained version
numbers without a module author having to implement N.N.N parsing and
comparing. I also expect the number of versions to be low.

James

Kris Zyp

unread,
Jan 6, 2011, 12:59:59 PM1/6/11
to comm...@googlegroups.com, James Burke
That sounds good to me.
Kris

--
Thanks,
Kris

James Burke

unread,
Jan 6, 2011, 1:08:21 PM1/6/11
to comm...@googlegroups.com
I updated the API page here:

http://wiki.commonjs.org/wiki/Modules/AsynchronousDefinition#define.amd_property

Changes from initial proposal:

* Version will likely be specified by the property name instead of a
property inside the define.amd object. So, define.amd = {} indicates
that the current version of the API is supported.

James

Reply all
Reply to author
Forward
0 new messages