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 torequire()
, each defining it differently. (The snippet appears to follow CommonJS-style.) – Jonathan Lonowski Commented Feb 23, 2016 at 4:53
2 Answers
Reset to default 4require
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.