English 中文(简体)
自我援引职能范围内休养职能的时间安排
原标题:setTimeout() on recursive function within a self invoking function

正如我看到的,我要把我的法典作为自我挑动的匿名职能散发。 此外,根据我的守则,我必须监测另一个校准负荷,因此,我可以在可用时使用。

(function(window, document, undefined) {
  staffHappens();
  var initMyLib = function() {
    if (typeof(myLib) ==  undefined ) {
      setTimeout("initMyLib()", 50);
    } else {
      useMyLib();
    }
  }
  moreStaffHappens();
  initMyLib(); //-> initMyLib is undefined
})(this, document);

如何发生这一错误? InitMyLib是否属于封装(自发)功能的范围?

最佳回答

更改<代码>准时”(“initMyLib()”),50;至settimeout(initMyLib, 50);

当你提出论据时,它将试图在时间外出时加以评价,但时间范围将遍及全球。 在全球范围不存在你的方法。


http://jsfiddle.net/gaby/zVr7L/“rel=“noretinger”http://jsfiddle.net/gaby/zVr7L/

问题回答

You could also use a real anonymous function to avoid scoping issues:

(function() {
    if(typeof(myLib) ==  undefined )
        setTimeout(arguments.callee, 50);
    else
        // loaded
})()




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签