I have been trying to write getters and setters using object.defineproperty,but could not .I have been trying this example but it throws an error as no firstName property defined.can someone please help me this
function person(fName, lName) {
Object.defineProperty(this, 'firstName', {
get:function() { return firstName; },
set:function(newValue){firstName=newValue;}
});
}
var p1=person("xyz","abc");
console.log(p1.firstName);
Thanks