最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

What is Javascript 'require'? - Stack Overflow

programmeradmin3浏览0评论

I was analyzing javascript codes in a chrome extension and noticed this in it.

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 ?

I was analyzing javascript codes in a chrome extension and noticed this in it.

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 ?

Share Improve this question edited Mar 3, 2016 at 11:41 Sungguk Lim 6,2287 gold badges46 silver badges64 bronze badges asked Feb 23, 2016 at 4:42 Aravind KrishnaAravind Krishna 1591 gold badge3 silver badges10 bronze badges 2
  • 9 Possible duplicate of What is this Javascript "require"? – jmargolisvt Commented Feb 23, 2016 at 4:47
  • 1 require() isn't a keyword. It's a function defined either by the environment (Node.js), a library (e.g. RequireJS), or a build tool (e.g., Browserify). AMD and CommonJS are the mon standards related to require(), each defining it differently. (The snippet appears to follow CommonJS-style.) – Jonathan Lonowski Commented Feb 23, 2016 at 4:53
Add a ment  | 

2 Answers 2

Reset to default 4

require method is part of the monjs file and module loader. You can check more details in their Sample page.

You may be looking for 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.

发布评论

评论列表(0)

  1. 暂无评论