250307.1 · b989f98033b7eb061e875b8137d670d8a20c259b
refactor: use const to replace var (#593)
reading declarations
Changes to src/5-async-work/async_pi_estimate/node-addon-api/addon.js. All files
src/5-async-work/async_pi_estimate/node-addon-api/addon.js
@@ -1,5 +1,5 @@-var addon = require('bindings')('addon');-var calculations = process.argv[2] || 100000000;+const addon = require('bindings')('addon');+const calculations = process.argv[2] || 100000000; function printResult(type, pi, ms) { console.log(type, 'method:');@@ -10,19 +10,19 @@ function printResult(type, pi, ms) { } function runSync() {- var start = Date.now();+ const start = Date.now(); // Estimate() will execute in the current thread, // the next line won't return until it is finished- var result = addon.calculateSync(calculations);+ const result = addon.calculateSync(calculations); printResult('Sync', result, Date.now() - start); } function runAsync() { // how many batches should we split the work in to?- var batches = process.argv[3] || 16;- var ended = 0;- var total = 0;- var start = Date.now();+ const batches = process.argv[3] || 16;+ let ended = 0;+ let total = 0;+ const start = Date.now(); function done (err, result) { total += result;@@ -35,7 +35,7 @@ function runAsync() { // for each batch of work, request an async Estimate() for // a portion of the total number of calculations- for (var i = 0; i < batches; i++) {+ for (let i = 0; i < batches; i++) { addon.calculateAsync(calculations / batches, done); } }