。 除非你做一些事情,否则不能从<条码>这一条外查阅。
但我并不认为你需要额外的间接层面:
google.setOnLoadCallback(function(){$(document).ready(CareersInit);});
function CareersInit()
{
CAREERS = new Careers();
CAREERS.init();
}
function Careers()
{
var self = this;
this.init = function()
{
//Usual google maps stuff here
};
$( body ).bind( onload , function() {
self.init();
});
}
另外,你的法典正试图将<条码>(Careers>>例两例引入。 页: 1 页: 1 有<代码>Careers 构造单页载荷排印。 (每当谷歌火灾时,则可能无法操作)
我删除了其中一条电话:init
。
在对另一个答复发表评论时,你说,你想知道“最佳”方式是什么。 我不得不更多地了解你要做的事情,但我可能这样做:
(function() {
// Our single Careers instance
var CAREERS;
// Ask Google to call us when ready
google.setOnLoadCallback(function(){
// Just in case Google is ready before the DOM is,
// call our init via `ready` (this may just call
// us immediately).
$(document).ready(CareersInit);
});
// Initialize our single instance
function CareersInit()
{
CAREERS = new Careers();
CAREERS.init();
}
// Constructor
function Careers()
{
}
// Career s init function
Careers.prototype.init = Careers_init;
function Careers_init()
{
//Usual google maps stuff here
}
})();
......除非你只想到one<>>>>> 例(而且你确信不会改变),否则根本就没有要求施工人员:
(function() {
// Our data; the function *is* the single object
var someData;
// Ask Google to call us when ready
google.setOnLoadCallback(function(){
// Just in case Google is ready before the DOM is,
// call our init via `ready` (this may just call
// us immediately).
$(document).ready(CareersInit);
});
// Initialize our single instance
function CareersInit()
{
someData = "some value";
}
})();
There, the function scope is the single instance; no need for separate constructor functions, playing games with this
, etc. Note that we re not creating any globals, someData
is scoped to the anonymous function. The call that the interpreter makes to that function is our single object.
If you re ever going to need more than one Career
instance, then great, definitely go the constructor function route. But if not, there s a lot less fuss involved if you use the object you already have (the execution context of the call to the function).
<>Off-topic:Strongly,建议宣布CAREERS
。 您的代码目前为rel=“nofollow”>。