Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Using Object.create
- const personPrototypes = {
- greeting: function(){
- return `Hello there ${this.firstName} ${this.lastName}!`;
- },
- getsMarried: function(newLastName){
- this.lastName = newLastName;
- }
- }
- const mary = Object.create(personPrototypes);
- mary.firstName = 'Mary';
- mary.lastName = 'Williams';
- mary.age = 30;
- mary.getsMarried('Thompson');
- console.log(mary.greeting());
- const brad = Object.create(personPrototypes, {
- firstName: {value: 'Brad'},
- lastName: {value: 'Traversy'},
- age: {value: 36}
- });
- console.log(brad);
- console.log(brad.greeting());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement