Skip to content

Instantly share code, notes, and snippets.

@eliza-abraham
Last active August 29, 2015 14:15
Show Gist options
  • Save eliza-abraham/9e52443a0243daaa0aaa to your computer and use it in GitHub Desktop.
Save eliza-abraham/9e52443a0243daaa0aaa to your computer and use it in GitHub Desktop.
Object Oriented Javascript : Prototypal Approach
// Prototypal Approach
var person = {
firstName: 'Anonymous',
lastName: 'Not Known',
create: function(firstName, lastName) {
self = Object.create(this);
self.firstName = firstName;
self.lastName = lastName;
return self;
},
fullName: function() {
return(this.firstName + ' ' + this.lastName);
},
introduce: function() {
return('Hello! I am ' + this.fullName() + '. Pleased to meet you!');
}
}
var ema = person.create('Eliza', 'Abraham');
ema.introduce();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment