如何复制javascript范围?通过使用for循环?

时间:2011-11-03 09:58:35

标签: javascript comet

我只是让这个javascript彗星呼叫正常工作,但发现我需要30件来做同样的功能,但具有不同的值输出。看看我的代码

   <script type="text/javascript">
   var Comet = Class.create();
   Comet.prototype = { 
    timestamp: 0,
    url: 'backend.php',  
    noerror: true,
    pointname: 'GrossElectricityGeneration',
   initialize: function() { }, 
  connect: function()
  {
  this.ajax = new Ajax.Request(this.url, {
  method: 'get',
  parameters: { 'timestamp' : this.timestamp, 'pointname': this.pointname},
  onSuccess: function(transport) {
    // handle the server response
    var response = transport.responseText.evalJSON();
    this.comett.timestamp = response['timestamp'];
    this.comett.handleResponse(response);
    this.comett.noerror = true;
    },
    onComplete: function(transport) {
    // send a new ajax request when this request is finished
    if (!this.comett.noerror)
      // if a connection problem occurs, try to reconnect each 5 seconds
      setTimeout(function(){ comett.connect() }, 5000); 
    else
      this.comett.connect();
    this.comett.noerror = false;
     }
  });
  this.ajax.comett = this;
 },

 disconnect: function()
{
 },

 handleResponse: function(response)
 {

  $('page1b').innerHTML = '<div>' + response['msg'] +'</div>'; 
 $('page1c').innerHTML = '<div>' + '67'+'</div>';    
  }, 
 }

  var comett = new Comet();
 comett.connect();
 </script>

要做到这一点,一个愚蠢的方法是复制30件......并重命名 comett到30个不同的名字 30种不同的#('page1a')#('page1b') 和点名称

有没有其他方法可以用于循环复制带有不同变量的30个副本?

感谢....

0 个答案:

没有答案