
Untitled
By: a guest on
May 7th, 2012 | syntax:
None | size: 1.11 KB | hits: 11 | expires: Never
Understanding variable scoping with async statements
for (var CurrentRow=0;CurrentRow < qryMfg.RecordCount;CurrentRow++){
console.log(qryMfg.MFGID[CurrentRow]);
dbo.transaction(function(myTrans) {
console.log(qryMfg.MFGID[CurrentRow]);
});
}
function create_handler( scoped_row ) {
return function(myTrans) {
console.log(qryMfg.MFGID[scoped_row]);
};
}
for (var CurrentRow=0;CurrentRow < qryMfg.RecordCount;CurrentRow++) {
console.log(qryMfg.MFGID[CurrentRow]);
dbo.transaction( create_handler(CurrentRow) );
}
function create_transaction( scoped_row ) {
console.log(qryMfg.MFGID[scoped_row]);
dbo.transaction( function(myTrans) {
console.log(qryMfg.MFGID[scoped_row]);
});
}
for (var CurrentRow=0;CurrentRow < qryMfg.RecordCount;CurrentRow++) {
create_transaction( CurrentRow );
}
for (var CurrentRow=0;CurrentRow < qryMfg.RecordCount;CurrentRow++) {
console.log(qryMfg.MFGID[CurrentRow]);
(function(row) {
dbo.transaction(function(myTrans) {
console.log(qryMfg.MFGID[row]);
});
})(CurrentRow);
}