直接引用参数属性js

Directly reference parameter properties js

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

该模块非常大,会增加页面加载时间,不应在顶层通过 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.
  });

}

这会非常相似!

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