@@ -98,7 +98,7 @@ in `build/Release/`.
98
98
You can now use the binary addon in a Node project ` hello.js ` by pointing ` require ` to
99
99
the recently built ` hello.node ` module:
100
100
101
- var addon = require('./build/Release/hello');
101
+ const addon = require('./build/Release/hello');
102
102
103
103
console.log(addon.hello()); // 'world'
104
104
@@ -175,7 +175,7 @@ function calls and return a result. This is the main and only needed source
175
175
176
176
You can test it with the following JavaScript snippet:
177
177
178
- var addon = require('./build/Release/addon');
178
+ const addon = require('./build/Release/addon');
179
179
180
180
console.log( 'This should be eight:', addon.add(3,5) );
181
181
@@ -215,7 +215,7 @@ adding the function as a property of `exports`.
215
215
216
216
To test it run the following JavaScript snippet:
217
217
218
- var addon = require('./build/Release/addon');
218
+ const addon = require('./build/Release/addon');
219
219
220
220
addon(function(msg){
221
221
console.log(msg); // 'hello world'
@@ -251,10 +251,10 @@ the string passed to `createObject()`:
251
251
252
252
To test it in JavaScript:
253
253
254
- var addon = require('./build/Release/addon');
254
+ const addon = require('./build/Release/addon');
255
255
256
- var obj1 = addon('hello');
257
- var obj2 = addon('world');
256
+ const obj1 = addon('hello');
257
+ const obj2 = addon('world');
258
258
console.log(obj1.msg+' '+obj2.msg); // 'hello world'
259
259
260
260
@@ -293,9 +293,9 @@ wraps a C++ function:
293
293
294
294
To test:
295
295
296
- var addon = require('./build/Release/addon');
296
+ const addon = require('./build/Release/addon');
297
297
298
- var fn = addon();
298
+ const fn = addon();
299
299
console.log(fn()); // 'hello world'
300
300
301
301
@@ -398,9 +398,9 @@ prototype:
398
398
399
399
Test it with:
400
400
401
- var addon = require('./build/Release/addon');
401
+ const addon = require('./build/Release/addon');
402
402
403
- var obj = new addon.MyObject(10);
403
+ const obj = new addon.MyObject(10);
404
404
console.log( obj.plusOne() ); // 11
405
405
console.log( obj.plusOne() ); // 12
406
406
console.log( obj.plusOne() ); // 13
@@ -411,9 +411,9 @@ Test it with:
411
411
This is useful when you want to be able to create native objects without
412
412
explicitly instantiating them with the ` new ` operator in JavaScript, e.g.
413
413
414
- var obj = addon.createObject();
414
+ const obj = addon.createObject();
415
415
// instead of:
416
- // var obj = new addon.Object();
416
+ // const obj = new addon.Object();
417
417
418
418
Let's register our ` createObject ` method in ` addon.cc ` :
419
419
@@ -528,14 +528,14 @@ The implementation is similar to the above in `myobject.cc`:
528
528
529
529
Test it with:
530
530
531
- var createObject = require('./build/Release/addon');
531
+ const createObject = require('./build/Release/addon');
532
532
533
- var obj = createObject(10);
533
+ const obj = createObject(10);
534
534
console.log( obj.plusOne() ); // 11
535
535
console.log( obj.plusOne() ); // 12
536
536
console.log( obj.plusOne() ); // 13
537
537
538
- var obj2 = createObject(20);
538
+ const obj2 = createObject(20);
539
539
console.log( obj2.plusOne() ); // 21
540
540
console.log( obj2.plusOne() ); // 22
541
541
console.log( obj2.plusOne() ); // 23
@@ -662,10 +662,10 @@ The implementation of `myobject.cc` is similar as before:
662
662
663
663
Test it with:
664
664
665
- var addon = require('./build/Release/addon');
665
+ const addon = require('./build/Release/addon');
666
666
667
- var obj1 = addon.createObject(10);
668
- var obj2 = addon.createObject(20);
669
- var result = addon.add(obj1, obj2);
667
+ const obj1 = addon.createObject(10);
668
+ const obj2 = addon.createObject(20);
669
+ const result = addon.add(obj1, obj2);
670
670
671
671
console.log(result); // 30
0 commit comments