【问题标题】:Directly reference parameter properties js直接引用参数属性js
【发布时间】:2021-11-03 01:44:34
【问题描述】:

有谁知道在语法上是否可以将参数属性应用为父函数引用的局部范围方法。

模块非常大,会增加页面加载时间,不应通过顶级 import() 导入。

import {method1, method2, method3} from "./module.js" //not an option

//Working example.
$('some-id').on('click', () => {
   import ("./module.js") 
   .then( (module) => {
   module.method();
   module.method2();
   module.method3();
   // module methods...

   
  });
}
//Something along these lines.
$('some-id').on('click', () => {
   import ("./module.js") 
   .then( ( module ) => {
   method();
   method2();
   method3();
   //Apply the module methods to function scope without direct reference to the parameter
   //this would save some time and loads of repetition if possible, question is can anything similar be done.
  });

}

【问题讨论】:

    标签: javascript jquery import parameters lazy-loading


    【解决方案1】:

    这将非常相似!

    $('some-id').on('click', async () => {
      const { method, method2, method3 } = await import("./module.js");
      method();
      method2();
      method3();
    });
    

    【讨论】:

      猜你喜欢
      • 2018-10-11
      • 2014-06-27
      • 1970-01-01
      • 1970-01-01
      • 2017-03-17
      • 1970-01-01
      • 1970-01-01
      • 2023-03-14
      • 1970-01-01
      相关资源
      最近更新 更多