慕课闭包封装的笔记

xiaoxiao2021-02-28  17

//闭包的封装 (function(){ var _userID=123; var _typeID="item"; var myExport={}; function converter(userID){//个人认为这些函数就是闭包 return +userID; } myExport.getUserID=function(){ return converter(_userID); } myExport.getTypeID=function(){ return _typeID; } window.myExport=myExport; })(); var a=myExport.getUserID(); var b=myExport.getTypeID(); var c=myExport._userID; console.log(a); console.log(b); console.log(c); //123 //item //undefined
转载请注明原文地址: https://www.6miu.com/read-2150331.html

最新回复(0)