赞
踩
首先我们写一个简单的普通函数
const runOnce = function () {
console.log('This will never run again');
};
runOnce();
● IIFE的写入如下所示
(function () {
console.log('This will never run again');
});
● 如果想立刻调用它,写法如下
(function () {
console.log('This will never run again');
})();
● 当然IIFE也可以用箭头函数的方式展现出来
(() => console.log('This will ALSO never run again'))();
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。