Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Javascript Prototypes #167

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
- [Chaiyapat Tantiworachot](https://github.com/pixelart7)
- [Hamza Nasim](https://github.com/HamzaNasim)
22 changes: 22 additions & 0 deletions source/snippets/javascript/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ section: content
- [Useful Functions](#useful-functions)
- [Closures](#closures)
- [Destructuring](#destructuring)
- [Prototypes](#prototypes)]

## Variables

Expand Down Expand Up @@ -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");
```