in javascript why use " var that = this "
Posted
by
tarek11011
on Programmers
See other posts from Programmers
or by tarek11011
Published on 2011-03-17T06:39:45Z
Indexed on
2011/03/17
16:18 UTC
Read the original article
Hit count: 143
JavaScript
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
© Programmers or respective owner