Trying to learn how to create a durable object with JavaScript, but as you can see from the example below one can easily access any of the Person instance's members - What am I doing wrong?
function Person(name, age, job){
"use strict";
//create the object to return
var o = new Object();
//optional: define private variables/functions here
o.name = name;
o.age = age;
o.job = job;
//attach methods
o.sayName = function(){
alert(name);
};
//return the object
return o;
}
var newGuy = Person("Guy", 21, "Seeker");
newGuy.name; // "Guy" <- Shouldn't this return an error or "undefined"?