Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebug showing infinite recursion for constructor

I wanted to dig in into the language specific construct "prototype" of javascript. And here is my learning purpose code:

var f = function() {};
f.ext = 1;
f.prototype.pext = 2;

When i debug this code now with firebug, i get the following: enter image description here

Where does this infinite nesting come from? Let's begin from top (OK=unterstood):

f (OK)
- ext (OK)
- prototype (OK)
- pext (OK)
- constructor (I'm stuck at this point)

Whose constructor is that? And why do we have this infinte nesting?

like image 534
A.B. Avatar asked Feb 07 '13 21:02

A.B.


1 Answers

Its simply because f === f.prototype.constructor, those are the same and Firebug shows them as circular references.

The same as:

var a = {},
    b = a;
a.b = b;

You will see infinite references here too.

like image 51
Grzegorz Kaczan Avatar answered Sep 27 '22 23:09

Grzegorz Kaczan