I asked this question once before but did not get the result. Maybe my description was not clear enough. Now I have reorganized my thoughts. The details are as follows:
function demo(){
// 各种实现
}
demo(); // 我希望它默认就执行一次,所以就这么调用了。
窗口事件:
$(window).resize(function(){
demo(); // 这里也需要根据条件调用demo函数
});
The question is, is there a way to make the demo execute automatically for the first time? And then it can be called elsewhere? How to optimize such a code body, exclude: arguments.callee, please give me some advice... Thank you in advance.
不知道这样是否符合楼主要求
实现的方式有很多。匿名函数,自执行函数都可以。可参考下面:
楼主的意思是想要自行执行的匿名函数,然后另一个地方又想调用这个匿名函数吗?
你现在这个写法没什么毛病啊
自动运行的js就是(函数写在这)() 这种形式,你也可以window.onload事件调用一次啊