Javascript notes: deeply analyzes the creation (bottom) of objects in javascript-from object creation to javascript

Source: Internet
Author: User
Why do we need to create objects in mainstream programming languages? The following definition I want to give us an answer: the object definition in object-oriented language is: the object is anything that people want to study, from the simplest integer to the complex aircraft, it can be regarded as an object. It not only represents... syntaxHighlighter. all ();

 

Why do we need to create objects in mainstream programming languages? The following definition gives us an answer:

In object-oriented languages, objects are defined as anything that people want to study. From the simplest integer to the complex aircraft, objects can be viewed as objects, it not only represents specific things, but also abstract rules, plans, or events. Aside from these abstract definitions, we can understand from the underlying computer technology that objects are actually a way to store data.

Writing the next article in this series makes me really hard. I originally wanted to write closures and prototypes, but I always felt bad, when talking with a former colleague about javascript technology, he told us that no matter what kind of variables in computer languages are actually the way data is stored in computers. Programs are made up of data and operations, he said that since I am learning how to create javascript objects, you can think about what the created objects are like, in computer languages, no matter what you are creating, such as basic data types or complex data types, variables are actually variables, and variables are data in programs, the running of a program is the process of constantly retrieving the data, creating the data, then retrieving the data, repeating the loop, and finally making the data persistent. He also said, I often ask him to improve program performance, optimization program skills, so improving the data retrieval capability in the program is the ultimate program performance optimization.

I recently studied Yahoo's front-end technology to find out what this guy is talking about.

Yahoo's front-end technical force said:

There are four data storage methods in javascript (the most basic ):

Direct Volume

A direct volume only represents itself and does not store specific locations. The direct quantities in Javascript include strings, numbers, Boolean values, objects, arrays, and functions. Regular Expressions and special null and undefined expressions.

Variable

A data storage unit defined by a developer using the keyword var.

Array Element

It is stored in the javascript array object and indexed by numbers.

Object Member

Stored in a javascript Object and indexed by string.

Yahoo's front-end engineers tested the performance of these data storage methods. In most browsers, the speed of reading the direct volume and variables is much higher than that of reading array elements and object members. Maybe we can think about object creation in this way: Every time we create an object, we increase the complexity of data retrieval. if the object is nested, the performance loss will increase by a geometric multiple.

The creation of objects may be the beginning of the slow response of applications.

As I have said before, javascript can also use the phrase in java: Everything is an object, and even a function can be used as an object. In this case, creating a function is to create an object, and how to create this object is the key to improving the performance of the program.

It's a lot of knowledge to create a Function object in javascript. If we treat a Function as an object, some concepts that are hard to understand will be much better understood.

In this article, I talked about the scope. What is the scope? The Scope is actually an internal attribute [Scope] of the Function object instance ]. When a function is created, the internal attribute [Scope] contains a set of all objects in the Scope of the function. This set is called the Scope chain. The Scope chain determines the data that the function can access.

The following code creates a function add:

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.