Let's say I have 3 functions. If I write them all one by one, below each other, all of them will be exposed to the global namespace hence global polution. So one way seems to be the following.
var test;
(function() {
test.funct1 = function(){
}
test.funct2 = function(){
}
test.funct3 = function(){
}
})
Now, we reduced the problem since the functions are not put into the global namespace. We could say, they still are, but not completely. test
will be put on the global namespace
which would have all other functions on it.
Question 1) Now, the problem still exists, if someone or some library has test
, the problem is my test
and the library's test
will be collided, which seems too bad. How do people solve this without any library/framework or whatever (without webpack) ?
Question 2) Okay, so webpack does solve the above problem. In webpack, each file is the module. That's understandable, but still, a good nice example would be great, some stuff still have to be put on global scope. I'd appreciate a good nice example.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…