i saw a code where people used prototype keyword in javascript but i do not understand what is the importance of this keyword and when to use it.
here is some code related to javascript prototype
1st example
function Person(fn,ln)
{
this.FirstName = fn;
this.LastName = ln;
}
Person.prototype.GetFullName = function()
{
return this.FirstName + ' ' + this.LastName;
}
var p = new Person('jon','smith');
alert(p.GetFullName());
2nd example
function Person(fn,ln)
{
this.FirstName = fn;
this.LastName = ln;
Person.prototype.GetFullName = function()
{
return this.FirstName + ' ' + this.LastName;
}
}
var p = new Person('jon','smith');
alert(p.GetFullName());
1) just see the code what prototype keyword will do here?
2) also see two same code in 1st example prototype used outside of Person function and in second example prototype is wrapped in person function. looking for good explanation with more sample example to understand it properly . thanks