8

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 ?

Sungguk Lim
  • 6,109
  • 7
  • 43
  • 63
Aravind Krishna
  • 159
  • 1
  • 3
  • 10
  • 9
    Possible duplicate of [What is this Javascript "require"?](http://stackoverflow.com/questions/9901082/what-is-this-javascript-require) – jmargolisvt Feb 23 '16 at 04: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](https://github.com/amdjs/amdjs-api/blob/master/AMD.md) and [CommonJS](http://wiki.commonjs.org/wiki/Modules/1.1) are the common standards related to `require()`, each defining it differently. (The snippet appears to follow CommonJS-style.) – Jonathan Lonowski Feb 23 '16 at 04:53

2 Answers2

4

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

TeaCoder
  • 1,958
  • 13
  • 13
2

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.

Ankur Rana
  • 88
  • 9