Skip to content

Commit

Permalink
Prototypal Inheritance & OOP
Browse files Browse the repository at this point in the history
  • Loading branch information
willltns committed Jul 28, 2019
1 parent 4732668 commit 9c6be6c
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
28 changes: 28 additions & 0 deletions 5. The 2 Pillars Closures and Prototypal Inheritance/16 - 25.md
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)
54 changes: 54 additions & 0 deletions 6. Object Oriented Programming/1 - 18.md
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.

0 comments on commit 9c6be6c

Please sign in to comment.