什么是 Javascript '需要'?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35568985/
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
What is Javascript 'require'?
提问by Aravind Krishna
I was analyzing javascript codes in a chrome extension and noticed this in it.
我正在分析 chrome 扩展中的 javascript 代码,并在其中注意到了这一点。
require("name of required class/file/module") //Not sure whether it is class,file,module
May be its because I'm newbie to programming or something,but I cant find the 'require' keyword in javascript reference or documentation.There is 'import' statement for importing modules. I googled for require for javascript but all I can find is the 'require' for node.js, the server side scripting using javascript. I am talking about chrome extension/client side script.Does anyone have any idea about this ?
可能是因为我是编程新手,但我在 javascript 参考或文档中找不到“require”关键字。有用于导入模块的“import”语句。我在 google 上搜索了 javascript 的 require,但我能找到的只是 node.js 的“require”,使用 javascript 的服务器端脚本。我说的是 chrome 扩展/客户端脚本。有人对此有任何想法吗?
回答by TeaCoder
require
method is part of the commonjsfile and module loader.
You can check more details in their Sample page.
回答by Ankur Rana
You may be looking for requirejs.
您可能正在寻找requirejs。
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 这样的模块化脚本加载器将提高代码的速度和质量。