Skip to content

Instantly share code, notes, and snippets.

@appkr
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save appkr/e0fbaf7d640533d7158c to your computer and use it in GitHub Desktop.
Save appkr/e0fbaf7d640533d7158c to your computer and use it in GitHub Desktop.
JavaScript Constructor// source http://jsbin.com/xuvoga
var Person = function(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
};
// every object from Person has below properties.
Object.defineProperties(Person.prototype, {
sayHi : {
value : function () {
return "Hi there ?";
},
enumerable : true
},
fullName : {
get : function() {
return this.firstName + " " + this.lastName;
},
enumerable : true
}
});
var johnDoe = new Person("John", "Doe");
/*
johnDoe.sayHi();
Person.prototype.sayHi();
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment