-
Notifications
You must be signed in to change notification settings - Fork 47
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
Error when running example code for Javascript doc - String.match() #574
Comments
This is interesting. The same example works in the browser console, but fails in the interactive example's console, in both Firefox and Chrome. Firefox: "Error: t.constructor is undefined" I think it's very likely that this is due to a bug in the interactive examples code that implements console.log:
...so it's assuming that if it's being called, then the argument has a const paragraph = 'The quick brown fox jumps over the lazy dog. It barked.';
const capturingRegex = /(?<animal>fox|cat) jumps over/;
const found = paragraph.match(capturingRegex);
console.log(typeof found.groups); // "object"
console.log(typeof found.groups.constructor) // "undefined"
console.log(typeof found.groups.constructor.name) // "TypeError: found.groups.constructor is undefined" @schalkneethling , what do you reckon? |
Will take a look. Thanks for the heads up, @wbamberg |
@wbamberg Ok, so adding this solves the problem: if (!objectName.constructor || !objectName.prototype) {
var formattedChild = '';
var start = true;
for (var key in input) {
if (start) {
start = false;
} else {
formattedChild = formattedChild + ', ';
}
formattedChild =
formattedChild + key + ': ' + this.formatOutput(input[key]);
}
return 'Object { ' + formattedChild + ' }';
} What I am really curious about is what type of
Are there other instances of this other than on |
Just to remember for later for myself (but if it's interesting to others) |
Searching the ECMAScript spec for uses of
So it is very uncommon. |
Thank you for the extremely valuable info @karlcow and @moztcampbell ❤️ |
* fix: add support for special object types in console Correctly print the value of objects such as those returned by named capture groups fix #574 * fix failing test
Was reading about String.match() and testing the example code snippets. The code snippet for Using named capturing groups does not work (see screenshot below)
The text was updated successfully, but these errors were encountered: