使用Javascript等功能响应等功能、Javascript

由网友(╮ 如果。涐解脱)分享简介:我有以下的code:myFunc的();酒吧();myFunc的()正在一个Ajax请求我不希望执行杆(),直到myFunc的()的要求已经完成。我也不想动调用bar()myFunc的内部。可能吗?修改的下面是code我结束了:VAR FOO = {初始化:功能(废话){//回调传递到了AJAX的挑战数据加载VAR回...

我有以下的code:

  myFunc的();
酒吧();
 

myFunc的()正在一个Ajax请求

我不希望执行杆(),直到myFunc的()的要求已经完成。

我也不想动调用bar()myFunc的内部。

可能吗?

修改的

下面是code我结束了:

  VAR FOO = {
 初始化:功能(废话)
 {
  //回调传递到了AJAX的挑战数据加载
  VAR回调= {
   myFunc1:函数(){myFunc1(等等); },
   myFunc2:函数(){myFunc2(等等); },
  };

  this.bar(回调); //将挑战数据和设置游戏
 },
 巴:函数(回调){..loop通过并执行它们..}

};
 
JavaScript 性能优化技巧分享

解决方案

为了做你在找什么,你必须找到一种方法的酒吧()的用的沟通myFunc的()的。

当你说你不希望将呼叫转移到的酒吧()的里面的 myFunc的()的这可能是PTED在几个方面除$ P $

例如,你可以做的酒吧()的的参数的 myFunc的()的

 函数bar(){
   //做吧()做
}

功能myFunc的(回调){
   //利用回调在xmlht prequest对象的onreadystatechange属性
}

myFunc的(巴)
 

我希望这会帮助你。

杰罗姆·瓦格纳

I have the following code:

myFunc();
bar();

myFunc() is making an ajax request

I don't want to execute bar() until myFunc()'s request has completed.

I also do not want to move the call to bar() inside of myFunc.

possible?

EDIT

Here is the code I ended up with:

var FOO = {
 init: function(blah)
 {
  // Callbacks to pass to the AJAX challenge data load
  var callbacks = {
   myFunc1: function(){ myFunc1(blah); },
   myFunc2: function(){ myFunc2(blah); },
  };

  this.bar(callbacks); // Load the challenge data and setup the game
 },
 bar: function(callbacks) { ..loop through and execute them.. }

};

解决方案

In order to do what you are looking for, you must find a way for bar() to communicate with myFunc().

When you say that you do not want to move the call to bar() inside myFunc() this can be interpreted in several ways.

For example, you could make bar() a parameter of myFunc()

function bar() {
   // do what bar() does
}

function myFunc(callback) {
   // use callback in the onreadystatechange property of the xmlhtprequest object
}

myFunc(bar)

I hope this will help you

Jerome Wagner

阅读全文

相关推荐

最新文章