I've always noticed this, but never actually understood what's happening here. I have a fairly simple object that I've put in a console.log
. It has a seemingly never ending pattern of prototype -> constructor -> prototype -> etc. What exactly is it's purpose?
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:
Sign up
Sign up
Here's how it works:
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
|
|||
|
It doesn't have a purpose. As you can see, it only annoys you without giving out any additional information. It only has a reason. What's happening is that the structure you're printing has a cyclical reference (the prototype knows about the contructor, and the constructor knows about its prototype), and the logger isn't smart enough to realize it will never finish if it naively follows all references. |
|||
|