84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
window.aaa = (function($) { var bbb = (function() { alert(1); })(); })(Zepto);
This is an encapsulated script. But how to call bbb outside?
aaa is mounted on the window, but aaa.bbb() cannot be executed
光阴似箭催人老,日月如移越少年。
You understand the timely function wrong:
1、(function(){})();即时函数,会执行一遍; 注:window.aaa = (function($) { })(Zepto); 你这里的 window.aaa是没有用的 是undefined; 你里面的bbb函数也是一样, 你外面当然访问不到呀!
Although I don’t quite understand how you want to call it, it seems that your aaa is mounted in the window, but aaa.bbb() cannot execute this sentence. Then you can change it to:
window.aaa = (function($) { var bbb = (function() { alert(1); }); return {bbb:bbb}; })(Zepto);
You can use aaa.bbb() outside; if you write it like this, you have to pay attention to the closure and variable scope issues in the bbb method~!
Use module.export to expose it and require it outside.
You understand the timely function wrong:
Although I don’t quite understand how you want to call it, it seems that your aaa is mounted in the window, but aaa.bbb() cannot execute this sentence. Then you can change it to:
You can use aaa.bbb() outside; if you write it like this, you have to pay attention to the closure and variable scope issues in the bbb method~!
Use module.export to expose it and require it outside.