Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 7th, 2012  |  syntax: None  |  size: 1.11 KB  |  hits: 11  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Understanding variable scoping with async statements
  2. for (var CurrentRow=0;CurrentRow < qryMfg.RecordCount;CurrentRow++){
  3.     console.log(qryMfg.MFGID[CurrentRow]);
  4.     dbo.transaction(function(myTrans) {
  5.         console.log(qryMfg.MFGID[CurrentRow]);
  6.     });
  7. }
  8.        
  9. function create_handler( scoped_row ) {
  10.     return function(myTrans) {
  11.         console.log(qryMfg.MFGID[scoped_row]);
  12.     };
  13. }
  14.        
  15. for (var CurrentRow=0;CurrentRow < qryMfg.RecordCount;CurrentRow++) {
  16.     console.log(qryMfg.MFGID[CurrentRow]);
  17.     dbo.transaction( create_handler(CurrentRow) );
  18. }
  19.        
  20. function create_transaction( scoped_row ) {
  21.     console.log(qryMfg.MFGID[scoped_row]);
  22.  
  23.     dbo.transaction( function(myTrans) {
  24.         console.log(qryMfg.MFGID[scoped_row]);
  25.     });
  26. }
  27.        
  28. for (var CurrentRow=0;CurrentRow < qryMfg.RecordCount;CurrentRow++) {
  29.     create_transaction( CurrentRow );
  30. }
  31.        
  32. for (var CurrentRow=0;CurrentRow < qryMfg.RecordCount;CurrentRow++) {
  33.     console.log(qryMfg.MFGID[CurrentRow]);
  34.  
  35.     (function(row) {
  36.         dbo.transaction(function(myTrans) {
  37.             console.log(qryMfg.MFGID[row]);
  38.         });
  39.     })(CurrentRow);
  40. }