<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script src="../js/jquery-1.8.1.min.js"></script>
</head>
<body>
<script type="text/javascript">
//闭包:模仿面向对象中类的私有字段,不给外部直接访问
// 闭包的范式:()();
(function () {
function Student() {
}
})();
//Student();//这里Student是访问不到的
//怎么才能访问到,间接访问!!!!!!!!!
(function (window) {
function A() {//私有的
alert("AAAAAAAAAAAA");
}
function B() {//私有的
}
window.A = A;//通过该方式可以让一个函数成为一个公开的函数
})(window);
//window.A();
//
(function (window) {
function A() {
B();
return {//暴露出多个函数
C: C,
D: D
};
}
function B() {
alert("BBBBBBBBBBBBBBB");
}
function C() {
alert("CCCCCCCCCCCCCC");
}
function D() {
alert('DDDDDDDDDDDDDDDDD');
}
window.A = A;
})(window);
var json = window.A();
json.C();
json.D();
</script>
</body>
</html>
js中的匿名函数
最新推荐文章于 2023-05-19 16:38:05 发布