What is 'typeof define === 'function' && define['amd']' used for?

What is 'typeof define === 'function' && define['amd']' used for?

This code checks for the presence of require.js, a JavaScript dependency management library.

If 'define' is not undefined and it is a function and 'amd' (asynchronous module definition) is also defined then the code assumes that require.js is in play.

If this is so then it defines 'factory' and passes jQuery to it as a dependency. Otherwise it sets up the dependencies that the code needs by attaching them to the root object.

As for what 'factory' is: it is not defined by the Javascript framework, it will be a function in the same file most likely. It will take the parameter jQuery.

猜你喜欢

转载自www.cnblogs.com/chucklu/p/11102944.html
今日推荐