javascript - Why there is a 'amd' property in 'define' function? -


i learning jquery , backbone source code, , noticed check if there requirejs:

jquery 1.9.1

if ( typeof define === "function" && define.amd && define.amd.jquery ) {     define( "jquery", [], function () { return jquery; } ); } 

backbone

if (typeof define === 'function' && define.amd) {     define(['underscore', 'jquery', 'exports'], function(_, $, exports) { 

why there have amd property in define function in requirejs?

and define.amd object key jquery true? have not import jquery module?

it convention amd loaders should use indicate define export global space define made used amd modules define themselves.

if amd loaders did not use convention if random javascript library decided export define function global space has nothing amd, code designed work or without amd loader erroneously believe used in environment amd loader present.

there still risk things go askew if random third party library decided export own define function (that has nothing defining amd modules) and decided add amd property it, risk lower if scheme explained above not used.

so jquery , backbone in code you've shown tests whether used in amd environment amd loader present, , if defines amd module.

define.amd.jquery specific jquery , indicates loader able account multiple version of jquery being loaded simultaneously.


Comments

Popular posts from this blog

java - Intellij Synchronizing output directories .. -

git - Initial Commit: "fatal: could not create leading directories of ..." -