es6 箭头函数->自执行函数

使用自执行函数能够确保该函数能够自行执行,而不需要额外编写代码执行它

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

猜你喜欢

转载自blog.csdn.net/weixin_34402090/article/details/91431364