function coolModule(){ var something = 'cool'; var another = [1,2,3]; function doSome(){ console.log(something); } function doanother(){ console.log( another.join( " ! " ) ); } return { dosome:doSome, doanother:doanother } } var obj = coolModule(); obj.dosome(); obj.doanother();
利用闭包的模块化