Last active
August 29, 2015 14:15
-
-
Save eliza-abraham/9e52443a0243daaa0aaa to your computer and use it in GitHub Desktop.
Object Oriented Javascript : Prototypal Approach
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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