hi i am new with javascript
What is the benefit of using this line
var that = this
An example
function Person( firstname, lastname, age ) {
this.firstname = firstname;
this.lastname = lastname;
this.age = age;
getfullname = function() {
return firstname + “ “ + lastname; }
var that = this;
this.sayHi = function() {
document.write( “Hi my name is “ + getfullname() + “ and I am “ + that.age + “years old.”);
} }
thanks
thisis context sensitive. Usingthatmakes sure that whensayHiis called it can use thethisvalue from whengetfullnamewas called.