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