doc: note util.isError() @@toStringTag limitations
util.isError() is the only remaining util.is*() method that depends on Object.prototype.toString() behavior. This commit notes the limitations of isError() related to @@toStringTag. Refs: https://github.com/nodejs/node/pull/2201 PR-URL: https://github.com/nodejs/node/pull/5414 Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
This commit is contained in:
parent
33e51fe18c
commit
54cbf2826b
@ -335,6 +335,22 @@ util.isError({ name: 'Error', message: 'an error occurred' })
|
||||
// false
|
||||
```
|
||||
|
||||
Note that this method relies on `Object.prototype.toString()` behavior. It is
|
||||
possible to obtain an incorrect result when the `object` argument manipulates
|
||||
`@@toStringTag`.
|
||||
|
||||
```js
|
||||
// This example requires the `--harmony-tostring` flag
|
||||
const util = require('util');
|
||||
const obj = { name: 'Error', message: 'an error occurred' };
|
||||
|
||||
util.isError(obj);
|
||||
// false
|
||||
obj[Symbol.toStringTag] = 'Error';
|
||||
util.isError(obj);
|
||||
// true
|
||||
```
|
||||
|
||||
## util.isFunction(object)
|
||||
|
||||
Stability: 0 - Deprecated
|
||||
|
Loading…
x
Reference in New Issue
Block a user