R
R
Robert2015-10-26 19:32:42
JavaScript
Robert, 2015-10-26 19:32:42

How to structure js code in a project?

Suppose there is a task: to send an ajax request with certain data at certain intervals.
The data is generated on the client side. Trace-but, there is acc. js code that handles all the necessary stuff.
But here's the problem: in fact, one file (let's call it main.js) is involved in solving the problem, and everything is stored in it: Functions that process data, functions responsible for the timer, a function that sends a request ...
I want some modularity. But how to do that? You can't write something like require "something there" in js.
How do they act in such situations? Or is it the norm?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bromzh, 2015-10-26
@Jowan

There is require.js, there is commonjs, there are es6 modules (this is a new standard, but now you can compile with babel and use polyfills), there are typescript modules, there are coffescript modules. Individual frameworks (like angular) have their own module systems.
Personally, I use requirejs at work. Pretty handy for those who can't use es6. It is mastered in 10-15 minutes, the Internet is full of information.

R
Rikcon, 2015-10-26
@Rikcon

You can't write something like require "something there" in js.

Can !
requirejs.org

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question