JS Fundamentals - Object Literal w/factory method
by smichelotti
JavaScript
var person = {
firstName: "abc",
lastName: "xyz",
sayHello: function(){
console.log("hello, my name is: " + this.firstName + " " + this.lastName);
}
};
window.createPerson = function(){
return Object.create(person);
};
var person1 = createPerson();
person1.firstName = "Steve";
person1.lastName = "Michelotti";
console.log(person1);
person1.sayHello();
var person2 = createPerson();
person2.firstName = "Bob";
person2.lastName = "Smith";
console.log(person2);
person2.sayHello();
//console.log(typeof person2);