Comments (7)
Searching the ECMAScript spec for uses of OrdinaryObjectCreate(null)
I find a few:
- @@unscopables properties such as
[1,2,3][Symbol.unscopables]
import.meta
in modules- The regexp named capture groups described in their issue
So it is very uncommon.
from bob.
@MEF4232 Thank you for reporting this. @wbamberg Thank you for digging in, that is indeed the problem. As this is a problem with interactive examples/Bob I am moving the issue to the mdn/bob repo
from bob.
Just to remember for later for myself (but if it's interesting to others)
- Prototype methods, objects without proto
- createMatchResultTemplateObject with Indices has groups only property and createMatchResultTemplateObject
from bob.
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"
Chrome: "Error: Cannot read property 'name' of undefined"
I think it's very likely that this is due to a bug in the interactive examples code that implements console.log: formatOutput
is trying to work out what kind of thing it's trying to log, and if it thinks it's an object, calling formatObject
. In particular it is doing:
var objectName = input.constructor.name;
...so it's assuming that if it's being called, then the argument has a constructor
property. But in the browser console:
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?
from bob.
@schalkneethling , what do you reckon?
Will take a look. Thanks for the heads up, @wbamberg
from bob.
@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 Object
this is that has neither a constructor
nor a prototype
. According to the docs:
All objects (with the exception of objects created with Object.create(null)) will have a constructor property
Are there other instances of this other than on String.match
?
from bob.
Thank you for the extremely valuable info @karlcow and @moztcampbell ❤️
from bob.
Related Issues (20)
- Wrap localStorage read/write access in try-catch block
- Insufficient color contrast in the interactive examples HOT 1
- Utilize ES6 features HOT 3
- css-examples: Regressions in bob v3
- Invalid CSS after editing isn't highlighted
- CSS editor: ctrl-X ctrl-V doesn't work
- Copy to clipboard from 'Try it' is not working
- backdrop-filter demo says the feature is not supported by Safari (but it is) HOT 9
- Horizontal scrollbar obscures content HOT 2
- Interactive Example Search Box looks broken / not intended HOT 3
- Consider extending feature detections for CSS functions HOT 4
- Interactive examples ignore changes of color schemes when features are not supported HOT 2
- in "try it" section"copy" button is not functioning!! HOT 1
- Remove feature detection and hiding of demo's in unsupported browsers HOT 10
- Code snippet copy button not working HOT 6
- interactive examples: line numbers and code overlaps HOT 14
- HTML examples: sometimes line counter collapses HOT 7
- Bug: Line number in code snippets doesn't stay on the left side when scrolling HOT 11
- Interactive examples 2-column layout is not compatible with mobile HOT 5
- Code line numbers overlap with line content. HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bob.