使用自执行函数能够确保该函数能够自行执行,而不需要额外编写代码执行它
const test = (id => {
return {
getId() {
console.log(id);
}
};
})(18);
test.getId(); // 18
复制代码
console.log(
(id => {
return {
say() {
console.log(id);
},
aaa: 1111
};
})(10).aaa
); // 111
复制代码
转载于:https://juejin.im/post/5cf086db518825332550d094