The understanding of classes and objects in JS

Source: Internet
Author: User

class: a description of a collection of objects with the same characteristics;
object: An individual of a real existence;

* * Object-oriented rather than class-oriented.

1. All objects, inherit by the prototype chain, polymorphism by weak type, encapsulation ... Although it can be closed, but I personally more like Python, the underline represents the private style

2. Human beings, for example, refer to a range; an object: A person, for example, refers to a specific object in this range.

When function in 3.Javascript is a constructor, it is a class that, with the new operator, can return an object.
Of course, to generate an object, you can also use the literal form, such as var obj = {x:1, y:function () {}};
A class can be understood as a template, and an object is a concrete instance created from this template.

Instanceof determine whether an object belongs to a class

Object Instanceof Constructor
Own parent parent ....
Constructor determine the immediate parent


1.Object instanceof Function True
Object Instanceof Object True
function instanceof Function True

Function instanceof Object True
2.
var arr = new Array ();
var date = new Date ();
Arr instanceof Array True
Date Instanceof Date True

if (date.constructor==date) {alert (true)} True

Data.prototype.constructor=array

The understanding of classes and objects in JS

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.