var ele=document.getElementById('btn');
When writing native js, you need to obtain a large number of page elements. Now that there are too many global variables, how do you avoid being polluted?
phpcn_u15822017-05-19 10:13:18
Open namespace:
var name={};
name.common={};
name.fx={};
name.site={};
name.common.ele1= document.getElementById('btn' );
neme.fx.ele1= document.getElementById('btn2');
大家讲道理2017-05-19 10:13:18
Same upstairs, wrap one floor with IIFE
(function () {
var foo = '...';
var baar = '...';
})();
黄舟2017-05-19 10:13:18
Modular. requirejs/webpack/ES6 modules, variables are all private to the module.