Example,
function Person()
{
this.name = "XYZ"
this.address = "Somewhere"
this.displayPerson = function(){
alert(this.name + " lives at " + this.address);
}
}
// Call it as normal function instead of constructor using new
Person();
// members defined by "this" are available in current scope
console.log(name);
console.log(address);
console.log(displayPerson);
No comments:
Post a Comment