201506300917_ JavaScript authoritative Guide (sixth edition)-classes and modules, defining class three footwork, defining functions for simple classes (p200-210)

Source: Internet
Author: User
Tags instance method

I. Classes and modules

1. The implementation of the class is based on the prototype inheritance mechanism.

Two. Classes and prototypes

Three. Classes and constructors

1. The constructor is used to initialize the newly created object.

2. Use new, so the constructor simply initializes the object state.

3. Building a constructor is defining the class, so the first letter is capitalized .

4.

Four. Identification of constructors and classes

Five. Constrctor Properties

1. The value of the constructor property is a function object

For example:

var F = function () {}; This is a function object;

var p = f.prototype; Prototype Object

var c = p.constructor; Functions associated with a prototype object

F = = C //true

2. The prototype can be referenced in reverse constrctor;

For example:

Rang.prototype = {

Constructor:rang;

METHOD1: ...

METHOD2: ...

}

Six. Defining class three Footwork

1. First define a constructor and initialize the instance properties of the new object;

2. Define an instance method for the prototype of the constructor;

3. Define class fields and class properties for the constructor.

For example:

function DefineClass (constructor,methods,statics) {

if (methods) extend (constructor.prototype,methods);

if (statics) extend (constructor,statics);

return constructor;

}

201506300917_ JavaScript authoritative Guide (sixth edition)-classes and modules, defining class three footwork, defining functions for simple classes (p200-210)

Related Article

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.