js的IIFE

tech2025-08-01  14

IIFE:(Immediately-Invoked Function Expression)立即执行函数表达式 作用:可以隐藏实现,不会影响全局命名空间,用它来编写js模块。

(function(){//匿名函数自调用 console.log("hello"); })(); (function(){ var a=1; function test(){ console.log(++a); } window.$ = function(){ return { test:test } } })(); $().test();//2
最新回复(0)