As the title suggested, I'm trying to call the $(document).ready(function() {...}); from another file. The code snippet is as below:
正如标题所示,我正在尝试调用$(document).ready(function(){…});从另一个文件。代码片段如下:
Source file:
源文件:
$(document).ready(function () {
alert('document.ready function called!');
// a lot of code
}
And in the test file:
在测试文件中:
TestFile.prototype.testDocumentReadyContents = function () {
// test code here trying to call the document.ready function
}
I haven't had any success on it yet. I have tried document.ready.apply(), trigger('ready'), overriding the document.ready function... but just couldn't call it. FYI I'm invoking it as part of my unit test.
我还没有成功。我已经尝试过document.ready.apply(),触发器('ready'),重写文档。准备功能……但就是叫不出来。我将它作为单元测试的一部分进行调用。
Thanks.
谢谢。
1 个解决方案
#1
7
GOOD WAY
$(document).ready(documentReady);
function documentReady() {
alert('document.ready function called!');
// a lot of code
}
TestFile.prototype.testDocumentReadyContents = function () {
documentReady();
}
Hackish Way
TestFile.prototype.testDocumentReadyContents = function () {
$.readyList[0]();
}
#1
7
GOOD WAY
$(document).ready(documentReady);
function documentReady() {
alert('document.ready function called!');
// a lot of code
}
TestFile.prototype.testDocumentReadyContents = function () {
documentReady();
}
Hackish Way
TestFile.prototype.testDocumentReadyContents = function () {
$.readyList[0]();
}