不太明白你说的“随机函数”是什么意思。让一个函数只加载一次好办,比如下面这个函数f,第一次调用输出1,第二次调用不输出值。
function f() { if (f.init) { return; } else { console.log(1); f.init = true; }}