JS Object-oriented

Source: Internet
Author: User

Process oriented:
According to the logical writing, conforms to the computer execution thought. There is a clear start and end, and the process of implementing the intermediate gradually.
Object-oriented:
Look at objects from a human point of view, have subjectivity, different people, face the same object, get different properties and methods

A class is an abstraction of an object that is an instance of a class

JS No class concept, only the concept of the prototype
Instances of classes in other languages can only use properties and methods that are defined first by the class, and cannot be modified
JS can add properties and methods to an object dynamically, but only if the object has added properties and methods, properties and methods added for the prototype, all objects of that prototype have added properties and methods

I. Creating an Object

function people (Name,age) {

This.name=name;

This.age=age;

This.getname=function () {

return this.name;

}

}

Two. Calling objects

var peo= new people ();

Alert (peo.name+ "," +peo.age+ "," +peo.getname ");

Three. Object inheritance

1. Impersonation inheritance
Object impersonating law one:
This.inherit=people;
This.inherit (Name,age);
Delete This.inherit;

Object Impersonating Law II:
People.call (this,name,age); parameter comma delimited

Object Impersonating Law III:
People.apply (This,[name,age]); parameters are passed in an array


2. True inheritance: Prototype chain inheritance
Man.prototype = new People ();

Funciotn Man (name,age) {

This.constructor (name,age); Call the constructor of the parent class to pass the argument

}
  

JS Object-oriented

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.