Basic Javascript concepts

Source: Internet
Author: User

Data Types in javascript:

Original Type: Number, String, Boolean value. (Original value: null, undefined)

Object Type: Key-value pair, array, function, Global Object (MATH, JSON)


Concepts of packaging objects:

The String "aaa". len is not an object, but can call its attributes. This indicates that this is only a temporary object, which is created using new String () internally.


The original type is always unchangeable, so their values can be compared, but the object type is variable and their values cannot be compared.

Javascript prototype and inheritance:

Every object in Javascript is associated with another object. This object is _ proto _ (prototype object). Note that the prototype object here is not prototype.

Here, prototype refers to the prototype attribute of the constructor, which is the prototype attribute of the object created by the keyword new and constructor call.

The _ proto _ of the object instance points to the prototype of the object, while the _ proto _ of the object is null. For example:

var array = new Array();array.__proto__ === Array.prororype  //trueArray.__proro //null

Of course, you can also use Object. getPrototypeOf () instead of _ proto _ to get the prototype inherited by the Object. For example:

Object.getPrototypeOf(Array) === Array.__proto__;

Object. getPrototypeOf () to view prototype inheritance, for example:

Object.getPrototypeOf(Array.prototype) // Object  

We can see that the prototype of Array inherits the Object, so Array also has its own method, such as totring. We can see that all objects share a common prototype, that is, the Object is only a constructor. To access the Object, we only use Object... prototype.


For example, Object .. getPrototypeOf () is used to view custom inheritance.

function A(){};function B(){};A.prototype = new B();Object.getPrototypeOf(A.prototype) //B



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.