我正在浏览 file upload plugin的 javascript 代码。
有一个piece of code它检查 define 是否是一个函数并声明一些我猜的依赖
(function (factory) {
'use strict';
if (typeof define === 'function' && define.amd) {
// Register as an anonymous AMD module:
define([
'jquery',
'jquery.ui.widget'
], factory);
} else {
// Browser globals:
factory(window.jQuery);
}
}
代码上方的注释说 define 是全局的。但是我在使用 angularjs 构建的应用程序中没有它。
我在代码库中搜索了 define 的声明。但是找不到任何。我用谷歌搜索 AMD,我可以看到定义为 used here再次。
我的问题是“定义”在哪里定义?
最佳答案
define
是一个函数,其功能由 the Asynchronous Module Definition specification 定义. AMD 只是一个规范;有多种实现,RequireJS 就是其中之一。如果需要,您可以看到 RequireJS 如何实现它,但请记住,RequireJS 的 define
并不是唯一的 define
。
关于javascript - 此代码库中定义的函数 'define' 在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17894427/