Object-oriented programming

What is object-oriented programming?

Object Oriented Programming (OOP) is a computer Programming architecture. A basic principle of OOP is that computer programs are composed of a single unit or object that acts as a subroutine. OOP achieves the three main goals of software engineering: reuse, flexibility, and extensibility. OOP= Object + class + inheritance + polymorphic + message, where the core concepts are classes and objects

Bleep, bleep, bleep, bleep, bleep, bleep

I think object orientation is abstracting things into objects and giving them their own properties and methods. To execute it as an object.

For example: two puppies, Honghong and Lanlan, have a meal

With object-oriented thinking: Pull out the thing: dog, create a dog class (or constructor), give the dog the name attribute, give the dog the eating method, create instances of dogs named Red red and LAN LAN, and execute their own eating methods

To code:

/ / class

class Dog {
  constructor(name) {
    this.name = name
    this.eat = function() {
      console.log(this.name + 'eat'); }}}let hong = new Dog('red')

console.log(hong.eat())

// constructor form

function Dog (name) {
  this.name = name
  this.eat = function() {
    console.log(this.name + 'eat')}}let lanlan = new Dog('light light blue')

console.log(lanlan.eat())

Copy the code

Ps: Classes are the new basic syntactic sugar structure in ECMAScript, which still uses the concepts of stereotypes and constructors

The next thing we need to look at is constructors, prototypes, and prototype chains