A
A
AkanoCA2019-11-07 16:56:19
JavaScript
AkanoCA, 2019-11-07 16:56:19

How to use pure JS according to BEM?

Good day, friends!
The crux of the matter is this.
I'm still using pure JS and could you explain to me how to implement it correctly according to BEM.
Look, for each block, as I understand it, its own JS file is used, and then, as I understand it, all these JS files are combined into one. And since initially, at the coding stage, they are all in different files, it is rather difficult to keep track of the variables not being repeated in their names.
What would be the best way to avoid this problem without violating the BEM methodology?
At the moment I'm using a rather strange method and I'm not sure if it's good at all.
Here's an example of what I'm doing now, I'm just wrapping the code in a function with the same block name
. in html i have block with class .banner
And in JS:

(function banner () {
...  //некий код 
}());

I'm new and haven't thought of anything better yet.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Bogachev, 2019-11-07
@sfi0zy

according to BEM

For the sake of clarity, it is worth noting that if you read the source , it turns out that BEM is not only about the names of classes and the separation of everything by files, there is a whole set of tools included. If you want to use their entire stack, then you should start from there.
It would be logical to use modules (google -> es6 modules).
PS: And read about how scripts are assembled now - it's not just gluing everything into one file, everything is a little more complicated there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question