<script> //java.utils.ArrayList() //包(命名空间) /* var java = {}; java.utils = {}; java.utils.ArrayList = "asdfafsd"; java.utils.ArrayList; */ // ( function(){ var a = 5; var b = 100; window.c = 200;//把c暴露出去 d = 300;//这行代码也可以做到公布 } )(); //console.log(c); var result = (function(m,n){ return m + n;})(10,20); //console.log(result); function Person(){ var age = 1; this.getAge = function(){ return age ; } this.setAge = function(val){ age = val; } } var p = new Person(); p.setAge(20); console.log(p.getAge()); //Closure 闭包 </script>
转载于:https://www.cnblogs.com/goldlong/p/7904295.html