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 ?

2
  • 9
    Possible duplicate of What is this Javascript "require"? 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 common standards related to require(), each defining it differently. (The snippet appears to follow CommonJS-style.) Commented Feb 23, 2016 at 4:53

2 Answers 2

4

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

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.