JavaScript constructor problem

learn the constructor and encounter the following code when doing exercises

the code is as follows

function Fn(){
   return this;
}
Fn.prototype.getNum = function(){
    console.log(3);
};
new new Fn().getNum ();

Why is the output 3?

what I understand is the code new new Fn (). GetNum ();

var f = new Fn(); //=>  f 
new f.getNum();  //=>  fgetNum

Apr.06,2021

clipboard.png


fjs



Menu