title: Dynamic onclick function assignment with dynamic parameters in JavaScript?
body: <p>I have this code:</p>
  
  <pre><code>document.getElementById('img'+i).onclick = function(){popup_show('popup',array_msg[i]+'|||'+date('Y-m-d',strtotime(lec_date))+'-==-'+str_view_forConflict, 'AddEditSchedule;;popup_drag2;;EditSched;;'+String(array_msg_id[3])+';;view', 'popup_drag', 'popup_exit', 'screen-center', 0, 0);};
  </code></pre>
  
  <p>...but when I click on the image, the data of <code>array_msg[i]</code> is the last data of the loop, meaning the index is the length of the loop. I use IE for this.</p>
  
  <p>Please give me an idea on how to do this. In FF, it works fine because I use <code>setAttribute</code>.</p>
  
  <p>@bobince</p>
  
  <pre><code>document.getElementById('img'+i).onclick= popup_show.bind(window, 'popup',array_msg[i]+'|||'+date('Y-m-d',strtotime(lec_date))+'-==-'+str_view_forConflict,'AddEditSchedule;;popup_drag2;;EditSched;;'+array_msg_id[3]+';;view','popup_drag', 'popup_exit', 'screen-center', 0, 0    ); 
                  if (!('bind' in Function.prototype)) {
                      Function.prototype.bind= function(owner) {
                          var that= this;
                          var args= Array.prototype.slice.call(arguments, 1);
                          return function() {
                              return that.apply(owner,
                                  args.length===0? arguments : arguments.length===0? args :
                                  args.concat(Array.prototype.slice.call(arguments, 0))
                              );
                          };
                      };
                  }
  </code></pre>