Reading notes-You don't know the JS on-object

Source: Internet
Author: User

good to want the object ...

A different call location for a function causes the this binding object to be different. But what exactly is the object, and why bind them? (Yes, I don't understand it too)

  

Grammar

There are two forms of object declarations:

1. Literal volume = var obj = {...};

2. Construction form = var obj = new Object ();

The two forms of the generated objects are the same, the only difference is that you can add multiple key-value pairs in a literal declaration, and the construction form can only be added individually.

type

There are six main types in JS: string, number, booleam, null, Undefined, object.

Note that the simple data type itself is not an object, and null is sometimes treated as an object type, but this is actually a bug in the language itself, that is, the string object is returned when NULL is executed typeof null. In fact, NULL itself is the base type. (The principle is that, different objects at the bottom are represented as binary, in JS, the first three bits of the binary are 0 will be judged as the object type, the null binary representation is all 0, so the execution will return object.) )

One common mistake is ' everything is the object ', which shows it is wrong (I went and was cheated by the teacher).

In fact, JS has many special object subtypes, called complex basic types.

A function is a subtype of an object (technically called a callable object). The functions in JS are ' class citizens ' because they are essentially the same as normal objects, so you can manipulate functions like other objects.

An array is also a type of object.

built-in objects

JS has some object subtypes, which are often referred to as built-in objects.

Includes string, number, Boolean, Object, Function, Array, Date, RegExp, Error.

Built-in objects can be used as constructors to construct a new object of the corresponding subtype.

If you create a number, string (var str = ' Jimmy ', num = 1) in literal form, the call to the object method (length) is automatically converted to an object and the method is called and then reverted back to the base data type, which is not visible. But there is no need for performance specifically through the construction of the declaration of basic data, this conversion is very frequent, so the bottom has been optimized, the literal is better and faster.

Null and undefined do not have a corresponding construction form, only text form.

Date is constructed and has no literal form.

For object, Array, Function, regexp, whatever form is used is the objects.

Error objects are rarely created in code, and are typically created automatically when an exception is thrown. It can also be created in the form of New Error (), which is generally not a need.

Report error message, Vue source code with Console.error (), as follows:

    function (MSG, VM) {        if (Hasconsole && (!  config.silent) {            console.error ("[Vue warn]:" + msg + "" + (                ? Formatlocation (Formatcomponentname (VM)): ")            ;}    ;

  Specifically used to generate error message functions, jquery Source code is not seen, especially big or very intimate.

Content

  The object content consists of a key-value pair, which is more like a pointer that holds the address where the content is stored. (ES6 does not support strange keys, so you can only define keys with normal strings)

You can use the point access and [] access keys, the main difference being that the point Access property name must satisfy the naming specification of the identifier, and [] can accept any form of string.

There is another nuance:

    function fn (a) {        //undefined        //1    }    var obj = {        1,    }    fn (' ab ');

When accessing a property name as a parameter into a function, use [] access to get the result correctly.

In an object, the property name is always a string, and if the value of the remaining type is used as the property name, the ToString method is forced to be called.

    var obj = {}    obj[true] = 1;    obj[1] = 2;     = 3;    Console.log (obj[//1    //2    //3

  Fun!

Computable attribute Name

You can use an expression to evaluate a property name in ES6.

      

  

Reading notes-You don't know the JS on-object

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.