File tree 1 file changed +16
-0
lines changed
1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -3425,6 +3425,14 @@ console.log(copiedBuf.toString());
3425
3425
3426
3426
console .log (buf .toString ());
3427
3427
// Prints: buffer
3428
+
3429
+ // With buf.slice(), the original buffer is modified.
3430
+ const notReallyCopiedBuf = buf .slice ();
3431
+ notReallyCopiedBuf[0 ]++ ;
3432
+ console .log (notReallyCopiedBuf .toString ());
3433
+ // Prints: cuffer
3434
+ console .log (buf .toString ());
3435
+ // Also prints: cuffer (!)
3428
3436
```
3429
3437
3430
3438
``` cjs
@@ -3439,6 +3447,14 @@ console.log(copiedBuf.toString());
3439
3447
3440
3448
console .log (buf .toString ());
3441
3449
// Prints: buffer
3450
+
3451
+ // With buf.slice(), the original buffer is modified.
3452
+ const notReallyCopiedBuf = buf .slice ();
3453
+ notReallyCopiedBuf[0 ]++ ;
3454
+ console .log (notReallyCopiedBuf .toString ());
3455
+ // Prints: cuffer
3456
+ console .log (buf .toString ());
3457
+ // Also prints: cuffer (!)
3442
3458
```
3443
3459
3444
3460
### ` buf.swap16() `
You can’t perform that action at this time.
0 commit comments