In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
Most people don't understand the knowledge points of this article "what types of javascript objects are divided into", so Xiaobian summarizes the following contents for everyone, with detailed contents, clear steps and certain reference value. I hope everyone can gain something after reading this article. Let's take a look at this article "what types of javascript objects are divided into".
There are two types of JavaScript objects: 1. Host Objects, which are objects provided by the JavaScript host environment, and their behavior is completely determined by the host environment;2. Built-in Objects, which are objects provided by the JavaScript language.
Operating environment of this tutorial: Windows 7 system, Javascript version 1.8.5, Dell G3 computer.
In javascript, objects can be divided into two classes: host objects and built-in objects.
Host Objects: Objects provided by JavaScript host environments whose behavior is determined entirely by the host environment.
Built-in Objects: Objects provided by JavaScript
Intrinsic Objects: Object instances specified by the standard and created automatically with JavaScript runtime creation.
Native Objects: Objects that can be created by users using built-in constructors such as Array, RegExp, or special syntax.
Ordinary Objects: Objects created by {} syntax, Object constructor, or class keyword definition classes that can be inherited by prototypes.
host object
JavaScript hosts come in all sorts of shapes and sizes, but the ones most familiar to the front end are undoubtedly hosts in the browser environment. In the browser environment, we all know that the global object is the window, and the window has many attributes, such as document. In fact, the properties on this global object window come partly from the JavaScript language and partly from the browser environment. JavaScript standards specify global object properties, and W3C standards specify other properties of Window objects. Host objects are also divided into intrinsic and user-created, such as document.createElement, which can create DOM objects. The host also provides constructors, such as new Image to create img elements,
Built-in objects·Inherent objects
Intrinsic objects are instances of objects that are specified by the standard and automatically created as JavaScript runtime is created. Intrinsic objects are created before any JavaScript code is executed, and they often act like base libraries. The "class" we mentioned earlier is actually a kind of inherent object. The ECMA standard provides us with a list of 150+ intrinsic objects.
Built-in objects·Native objects
In JavaScript, objects that can be created by the language's own constructors are called native objects. In the JavaScript standard, more than 30 constructors are provided. According to my understanding, according to different application scenarios, I divided native objects into the following categories.
Through these constructors, we can create new objects with the new operation, so we call these objects native objects. Almost all of these constructors have capabilities that cannot be implemented in pure JavaScript code, nor can they be inherited using the class/extend syntax. Most of the objects created by these constructors use private fields, such as:
Error: [[ErrorData]]Boolean: [[BooleanData]]Number: [[NumberData]]Date: [[DateValue]]RegExp: [[RegExpMatcher]]Symbol: [[SymbolData]]Map: [[MapData]]
These fields prevent the prototypical inheritance method from working properly, so we can think of all these native objects as "privileged objects" designed for specific capabilities or performance.
Simulating Functions and Constructors with Objects: Function Objects and Constructor Objects
I introduced the general classification of objects earlier, but there is a different perspective on objects in JavaScript, which is to use objects to simulate functions and constructors. In fact, JavaScript reserves the private field mechanism for this class of objects and specifies the concept of abstract function objects and constructor objects.
The definition of a function object is: an object with [[call]] private field, and the definition of a constructor object is: an object with [[construct]] private field.
JavaScript replaces functions in general programming languages with object-simulated function designs, which can be called and passed parameters just like functions in other languages. Any host that provides "objects with [[call]] private fields" can be supported by JavaScript function call syntax.
We can say that any object that implements [[call]] is a function object that can be called as a function. If it implements [[construct]], it is a constructor object that can be called as a constructor.
For programmers who provide a runtime environment for JavaScript, the host objects and built-in objects we mentioned above (such as Symbol functions) can mimic functions and constructors as long as the fields match.
Of course, functions created by users with the function keyword must be both functions and constructors. However, their behavioral effects are not the same.
For hosts and built-in objects, their implementations [[call]](called as a function) and [[construct]](called as a constructor) are not always consistent.
[[call]] and [[construct]] always behave similarly for objects created by the user using the function syntax or Function constructor; they execute the same piece of code. Let's look at an example.
function f(){ return 1;}var v = f(); //Call f as a function var o = new f(); //Call f as a constructor
This rule causes an interesting phenomenon. If our constructor returns a new object, then the new object created by new becomes an object that is completely inaccessible outside the constructor, which can be "private" to some extent.
function cls(){ this.a = 100; return { getValue:() => this.a }}var o = new cls;o.getValue(); //100//a Objects with special behavior can never be accessed outside
In addition to the objects described above, there are some objects, both native and native, that behave quite differently from normal objects.
Their common subscript operations (i.e., using brackets or dots to access attributes) or prototype settings differ from ordinary objects, which I briefly summarize here.
Array: The length property of Array automatically changes based on the largest subscript.
Object.prototype: As the default prototype for all normal objects, it can no longer be prototyped.
String: In order to support subscript operations, the positive integer property of String is accessed by looking in the string.
Arguments: Non-negative integer subscript attributes of arguments are linked to the corresponding variables.
Module namespace object: There are many special places, completely different from general objects, try to use it only for import.
Type arrays and array buffers: associated with memory blocks, subscript operations are special.
bind function: associated with the original function.
The above is about the content of this article on "what types of javascript objects are divided into". I believe everyone has a certain understanding. I hope that the content shared by Xiaobian will be helpful to everyone. If you want to know more relevant knowledge content, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.