From b07c21dc0554dcb0d3a8ad5e51d25b05a3ead9c3 Mon Sep 17 00:00:00 2001 From: Hamza Nasim <hamzanasim_cs@yahoo.com> Date: Fri, 30 Oct 2020 08:42:34 -0700 Subject: [PATCH] Javascript Prototypes --- CONTRIBUTORS.md | 3 ++- source/snippets/javascript/index.md | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 28fe9ba..aeff41c 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -40,4 +40,5 @@ - [Rabin Khatiwada](https://github.com/rabinkhatiwada) - [Adrian Hernandez-Lopez](https://github.com/AdrianHL) - [Juan Benitez](https://github.com/juanbenitez) -- [Chaiyapat Tantiworachot](https://github.com/pixelart7) \ No newline at end of file +- [Chaiyapat Tantiworachot](https://github.com/pixelart7) +- [Hamza Nasim](https://github.com/HamzaNasim) \ No newline at end of file diff --git a/source/snippets/javascript/index.md b/source/snippets/javascript/index.md index 21109ab..977db12 100644 --- a/source/snippets/javascript/index.md +++ b/source/snippets/javascript/index.md @@ -17,6 +17,7 @@ section: content - [Useful Functions](#useful-functions) - [Closures](#closures) - [Destructuring](#destructuring) +- [Prototypes](#prototypes)] ## Variables @@ -1015,3 +1016,24 @@ const {name, ...rest} = obj; //extract 'name' property and assign the remaining console.log(name) // 'Foo' console.log(rest) // {age: 31, hobby: 'coding'} ``` + +--- + +## Prototypes +[Destructuring](https://https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object_prototypes) Prototypes are the mechanism by which JavaScript objects inherit features from one another.All JavaScript objects inherit properties and methods from a prototype. + + +#### Code +```javascript +function Person(first, last, age, eyecolor) { + this.firstName = first; + this.lastName = last; + this.age = age; + this.eyeColor = eyecolor; +} +var myFather = new Person("John", "Doe", 50, "blue"); +var myMother = new Person("Sally", "Rally", 48, "green"); +``` + + +