[英]How do I handle this document ready situation?
Hopefully a very simple question. 希望这是一个非常简单的问题。 I have some various js functions written as such:
我有一些这样写的各种js函数:
var app={
start:function(){
//do some stuff and call calculate
}, //end start
calculate:function(){
//do some more stuff
} //end calculate
}; //end var app
var neato={
go:function(){
//do some stuff and call creation
}, //end go
creation:function(){
//do some more stuff
} //end creation
}; //end var neato
Which I could then start as follows: 然后我可以开始如下:
$(document).ready(app.start);
$(document).ready(neato.go);
Is there any way I can combine starting both functions in one document ready request?? 有什么办法可以在一个文档准备好请求中组合启动两个功能? I just can't seem to figure it out despite trying a few different possibilities.
尽管尝试了几种不同的可能性,但我似乎还是无法弄清楚。
Use an anonymous function and manually call both: 使用匿名函数并手动调用两者:
$(document).ready(function () {
app.start();
neato.go();
});
If you need to have the value of this
be document
in those functions, then use .call(this)
instead of ()
. 如果您需要具有的价值
this
是document
中的这些功能,然后使用.call(this)
不是()
And if you need to pass the arguments from the handler, use .call(this, arguments)
. 如果需要从处理程序传递参数,请使用
.call(this, arguments)
。
What you have already will work just fine... but to make it shorter: 您已经拥有的将可以正常工作...但是要使其更简短:
$(function(){
app.start();
neato.go();
});
or 要么
function startingFunctions(){
app.start();
neato.go();
}
$(startingFunction);
(note: $(function(){..});
is the same as document.ready) (注意:
$(function(){..});
与document.ready相同)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.