“`
function Person(name, age)
{
this.name = name;
this.age = age;
this.Print = function()
{
document.write(this.name + ” ” + this.age + “<br>”);
}
}
So I’m trying to understand oop in javascript. I read that functions are by default objects. This means that the method **this.Print**this.Print
What is the difference between local scope variables and members? For example:
“`
function Person(name, age)
{
var name = name;
var age = age;
this.name = name;
this.age = age;
this.Print = function()
{
document.write(this.name + ” ” + this.age + “<br>”);
}
}
I understand that **this**this
But if the “`this**Person**this.Print**this.Print
I know its too many questions, but I want to clear all this in order to know exactly what I am doing.
One last thing. Can someone tell me what exactly is happening in the code bellow and why am I getting that output?
“`
function Person(name, age)
{
this.name = name;
this.age = age;
this.Print = function()
{
document.write(this.name + ” ” + this.age + “<br>”);
}
return this.Print;
}
var p = new Person(“Nick”, 20);
p();
var myPrint = Person(“Nick”, 20);
myPrint();
**Output
“`
Nick undefined
Nick 20