mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
doc: fix Buffer.from(object) documentation
Only strings are supported for objects supporting `Symbol.toPrimitive`. PR-URL: https://github.com/nodejs/node/pull/33327 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
1 parent
d85a933250
commit
b3f14df485
1 file changed
+3
-6
+3
-6
@@ -657,11 +657,8 @@ added: v8.2.0
|
||||
-->
|
||||
|
||||
* `object` {Object} An object supporting `Symbol.toPrimitive` or `valueOf()`.
|
||||
* `offsetOrEncoding` {integer|string} A byte-offset or encoding, depending on
|
||||
the value returned either by `object.valueOf()` or
|
||||
`object[Symbol.toPrimitive]()`.
|
||||
* `length` {integer} A length, depending on the value returned either by
|
||||
`object.valueOf()` or `object[Symbol.toPrimitive]()`.
|
||||
* `offsetOrEncoding` {integer|string} A byte-offset or encoding.
|
||||
* `length` {integer} A length.
|
||||
|
||||
For objects whose `valueOf()` function returns a value not strictly equal to
|
||||
`object`, returns `Buffer.from(object.valueOf(), offsetOrEncoding, length)`.
|
||||
@@ -672,7 +669,7 @@ const buf = Buffer.from(new String('this is a test'));
|
||||
```
|
||||
|
||||
For objects that support `Symbol.toPrimitive`, returns
|
||||
`Buffer.from(object[Symbol.toPrimitive](), offsetOrEncoding, length)`.
|
||||
`Buffer.from(object[Symbol.toPrimitive]('string'), offsetOrEncoding)`.
|
||||
|
||||
```js
|
||||
class Foo {
|
||||
|
||||
Reference in new issue
Block a user