-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
5. The 2 Pillars Closures and Prototypal Inheritance/16 - 25.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
## Prototypal Inheritance | ||
|
||
Inheritance is an object getting access to the properties and methods of another object through the prototypal chain. | ||
|
||
in JavaScript, we do not have classical inheritance, though the `class` keyword. it called *syntactic sugar*. | ||
|
||
`isPrototypeOf`. `hasOwnProperty`. | ||
|
||
##### 'object'.\_\_proto\_\_ === 'Constructor'.prototype | ||
|
||
```javascript | ||
var arr = [] | ||
|
||
// prototypal chain | ||
arr.__proto__ === Array.prototype | ||
Array.prototype.__proto__ === Object.prototype | ||
Object.prototype.__proto__ === null | ||
|
||
// Array Constructor and Object Constructor are also objects (functions). | ||
// they inherit from base Function. but as constructors, the `prototype` property matters. | ||
// Only function has `prototype` property. that's why function could be Constructor. | ||
Array.__proto__ === Function.prototype | ||
Object.__proto__ === Function.prototype | ||
``` | ||
|
||
[JavaScript Object Hierarchy](http://www.mollypages.org/tutorials/js.mp) | ||
|
||
[The JavaScript Object Paradigm and Prototypes Explained Simply](https://levelup.gitconnected.com/the-javascript-object-paradigm-and-prototypes-explained-simply-e9cb9eaa49aa) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Programming Paradigm | ||
- clear and understandable | ||
- easy to extend | ||
- easy to maintain | ||
- memory efficient | ||
- dry | ||
|
||
enable us to make complex code more organized. | ||
|
||
Scheme(function) + Java(object) ==> JavaScript | ||
|
||
## Object-Oriented Programming | ||
Bringing together the data and its behavior in a single location. modeling real world objects and relationships. | ||
|
||
1. copy and paste obj code --> 2. function factory --> 3. OOP | ||
|
||
#### `Object.create()` | ||
|
||
#### Constructor Function | ||
`new` keyword | ||
|
||
#### Prototypal-Based Programming & Class-Based Programming(syntactic sugar) | ||
prototype. `class` keyword. | ||
|
||
##### `public` & `private(`#`)` - in staging(2019-07-28) | ||
|
||
##### review `this` keyword: | ||
- `new` binding | ||
- implicit binding. inside obj. | ||
- explicit binding. `bind`. `call`. `apply` | ||
- arrow function. lexical binding. | ||
|
||
### Inheritance | ||
`extend` keyword. | ||
|
||
```javascript | ||
class B extends A {} | ||
|
||
B.prototype.__proto__ === A.prototype | ||
|
||
A.prototype.isPrototypeOf(B.prototype) | ||
``` | ||
|
||
### Four Pillars of OOP: | ||
- Encapsulation. | ||
wrap things are related. | ||
|
||
- Abstraction. | ||
hiding the complexity and creating simple interface. | ||
|
||
- Inheritance. | ||
avoid repetitive code, memory effeciency. | ||
|
||
- Polymorphism. the ability in programming to present the same programming interface for differing underlying forms. |