You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The semantics for the util is... functions are somewhat unexpected. For example, the documentation for util.isRegExp says:
Returns true if the given "object" is a RegExp. false otherwise.
But I'm seeing that util.isRegExp(Object.create(RegExp.prototype)) === false.
Can we clarify the documentation to explain why this is not a RegExp or change the semantics of isRegExp please? (Same goes with the other is functions.) Thanks.
The semantics almost certainly won't change. It is suggested you don't use these functions; I've been meaning to put deprecation notices into the docs.
How do you suggest we clarify that that won't work?
For posterity, the internals use Object.prototype.toString.call(input) === '[object RegExp]', since other methods can be bypassed, and this is the most reliable.
For posterity, the internals use Object.prototype.toString.call(input) === '[object RegExp]', since other methods can be bypassed, and this is the most reliable.
Symbol.toStringTag is implemented in Chrome and avalaible in io.js behind --es_staging flag.
Anyway - Object.create(RegExp.prototype) is not a RegExp.
> p = Object.create(RegExp.prototype);
{}
> p.compile()
illegal access
> p.source
'(?:)'
> p.test('aaa')
TypeError: Method RegExp.prototype.test called on incompatible receiver [object Object]
ES6 allows to create classes extending RegExps, but it isn't implemented in any engine yet.
@Fishrock123 thanks. I think the deprecation notice is a fine solution.
I'm not sure if it helps, but saying that the function returns true for objects created with the RegExp constructor would also be clear. (@Ginden a description what is not a RegExp is not necessarily useful.)
Activity
[-]Unexpected semantics for "is..."[/-][+]Unexpected semantics for util.is...[/+]Fishrock123 commentedon Jul 17, 2015
The semantics almost certainly won't change. It is suggested you don't use these functions; I've been meaning to put deprecation notices into the docs.
How do you suggest we clarify that that won't work?
For posterity, the internals use
Object.prototype.toString.call(input) === '[object RegExp]', since other methods can be bypassed, and this is the most reliable.Fishrock123 commentedon Jul 22, 2015
See also #2201
Ginden commentedon Jul 26, 2015
Symbol.toStringTagis implemented in Chrome and avalaible in io.js behind--es_stagingflag.Anyway -
Object.create(RegExp.prototype)is not a RegExp.ES6 allows to create classes extending RegExps, but it isn't implemented in any engine yet.
deian commentedon Jul 27, 2015
@Fishrock123 thanks. I think the deprecation notice is a fine solution.
I'm not sure if it helps, but saying that the function returns true for objects created with the
RegExpconstructor would also be clear. (@Ginden a description what is not a RegExp is not necessarily useful.)Fishrock123 commentedon Aug 25, 2015
Deprecated in the docs as of 93e2830, see #2447