In the following code, if I comment //alert("Your Name is: " +fname);
in the constructor function then 'alert(p1.fname);alerts "Suresh" and If I remove the comment out the
alert("Your Name is: " +fname);then browser console gives out the error
: fname is not defined`
function person () {
this.fname = "Suresh";
alert("Your Name is: " +fname);
}
var p1 = new person();
alert(p1.fname);
I am puzzled by this behaviour. Pls explain
thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…