-
Notifications
You must be signed in to change notification settings - Fork 30.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
doc: Add notes for using @@toStringTag #2201
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,6 +194,21 @@ Returns `true` if the given "object" is a `RegExp`. `false` otherwise. | |
util.isRegExp({}) | ||
// false | ||
|
||
note: This function uses `Object.prototype.toString.call` and check the returned value is `[object RegExp]`. However, `Symbol.toStringTag` can change the returned value directly. `Symbol.toStringTag` is enabled under `--harmony-tostring`. | ||
|
||
If the argument object is modified like below, this function does not work properly. | ||
|
||
var fakeRegExp = {}; | ||
fakeRegExp[Symbol.toStringTag] = 'RegExp'; | ||
util.isRegExp(fakeRegExp); | ||
// true but this is not object | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "an object" |
||
|
||
var regexp = /a/; | ||
util.isRegExp(regexp); | ||
// true | ||
RegExp.prototype[Symbol.toStringTag] = 'Array'; | ||
util.isRegExp(regexp); | ||
// false but this is RegExp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "a RegExp" |
||
|
||
## util.isDate(object) | ||
|
||
|
@@ -208,6 +223,9 @@ Returns `true` if the given "object" is a `Date`. `false` otherwise. | |
util.isDate({}) | ||
// false | ||
|
||
note: This function uses `Object.prototype.toString.call` and check the returned value is `[object Date]`. However, `Symbol.toStringTag` can change the returned value directly. | ||
|
||
see [an example in util.isRegExp](#util_util_isRegExp) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Capitalize and wrap here and below. |
||
|
||
## util.isError(object) | ||
|
||
|
@@ -222,6 +240,9 @@ Returns `true` if the given "object" is an `Error`. `false` otherwise. | |
util.isError({ name: 'Error', message: 'an error occurred' }) | ||
// false | ||
|
||
note: This function uses `Object.prototype.toString.call` and check the returned value is `[object Error]`. However, `Symbol.toStringTag` can change the returned value directly. | ||
|
||
see [an example in util.isRegExp](#util_util_isRegExp) | ||
|
||
## util.isBoolean(object) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Note:" (capitalize) and please wrap lines at 80 columns. I'd write 'enabled with' instead of 'enabled under'.