Skip to content Skip to sidebar Skip to footer

Function Nested Itself In The Prototype

Question1: I was experimenting with prototypes of the objects and constructors in JS, when I've noticed that: function f(a) { this.a = a; this.x = 1 } function f2(a) { this.

Solution 1:

Its the same infinite nesting like

look to the right ->             <- look to the left

so actually its quite finite ;)

prototype ->                   <- constructor

( hint: this answer works best on a 300px smartphone.. ;))

Solution 2:

It is the normal behavior. Something like :

function f() {
 this.a=0;
}

var obj= new f();

Causes the same loop: the constructor for obj is f(), and the prototype of this constructor has f() as constructor, and its prototype has f() as...

Post a Comment for "Function Nested Itself In The Prototype"