JavaScript 中的define([, function ]) 是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16950560/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 06:34:55  来源:igfitidea点击:

What is define([ , function ]) in JavaScript?

javascriptfunctionrequirejs-define

提问by vinzzz

I see this being used all the time in JavaScript:

我看到在 JavaScript 中一直在使用它:

define(['param1', 'param2'], function() {

});

What is the definefunction?

功能是什么define

采纳答案by Tom Studee

define() is part of the AMD spec of js

define() 是 AMD js 规范的一部分

See:

看:

Edit: Also see Claudio's answer below. Likely the more relevant explanation.

编辑:另请参阅下面克劳迪奥的回答。可能是更相关的解释。

回答by Claudio Redi

That's probably a requireJSmodule definition

这可能是一个requireJS模块定义

Check herefor more details

点击这里了解更多详情

RequireJS is a JavaScript file and module loader. It is optimized for in-browser use, but it can be used in other JavaScript environments, like Rhino and Node. Using a modular script loader like RequireJS will improve the speed and quality of your code.

RequireJS 是一个 JavaScript 文件和模块加载器。它针对浏览器中的使用进行了优化,但也可以在其他 JavaScript 环境中使用,例如 Rhino 和 Node.js。使用像 RequireJS 这样的模块化脚本加载器将提高代码的速度和质量。