我正在尝试运行局部函数,但是我想从导入的模块内部触发它。这将是其工作原理的草图...有任何建议吗?
index.js
import { runBar } from "myModule.js";
runBar();
function foo() {
console.log('foo should run whenever bar is executed');
}
myModule.js
export function runBar(){
bar();
}
function bar() {
console.log("bar is running...");
//I want to call foo from here...
}
foo
作为参数传递呢?
index.js
import { runBar } from "myModule.js";
runBar(foo);
function foo() {
console.log('foo should run whenever bar is executed');
}
myModule.js
export function runBar(foo){
bar(foo);
}
function bar(foo) {
console.log("bar is running...");
//I want to call foo from here...
foo();
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句