In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "what are the javascript object types". In the daily operation, I believe many people have doubts about the javascript object types. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "what are the javascript object types?" Next, please follow the editor to study!
There are three object types of javascript: 1, internal objects, including local objects that need to be instantiated to use and built-in objects that do not need instantiation; 2, host objects, which are objects provided by the environment that execute JS scripts; and 3, custom objects, which are defined by developers themselves.
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
Objects in javascript can be divided into three categories, namely, internal objects (local objects and built-in objects), host objects, and custom objects.
1. Internal object
1), local objects, objects provided by ECMAScript that need to be instantiated (new) to be used:
Object 、 Function 、 Array 、 String 、 Boolean 、 Number 、 Date 、 RegExp 、 Error 、 EvalError 、 RangeError 、 ReferenceError 、 SyntaxError 、 TypeError 、 URIError
2) built-in objects, objects provided by ECMAScript that can be used without instantiation:
Only Global (global object) and Math
Math object Properties
Property description E returns the arithmetic constant e, the base of the natural logarithm (about 2.718). LN2 returns the natural logarithm of 2 (approximately 0.693). LN10 returns the natural logarithm of 10 (approximately 2.302). LOG2E returns the logarithm of e with base 2 (approximately equal to 1.4426950408889634). LOG10E returns the logarithm of e with a base of 10 (about 0.434). PI returns pi (approximately 3.14159). SQRT1_2 returns the reciprocal of the square root of 2 (approximately 0.707). SQRT2 returns the square root of 2 (about 1.414).
Math object method
Method describes that abs (x) returns the absolute value of x. Acos (x) returns the inverse cosine of x. Asin (x) returns the arcsine of x. Atan (x) returns the arc tangent of x as a value between-PI/2 and PI/2 radians. Atan2 (y PI/2 x) returns the angle from the x axis to the point (x moment y) (between-and PI/2 radians). Ceil (x) logarithm is rounded up. Cos (x) returns the cosine of the number. Exp (x) returns the index of Ex. Floor (x) rounds x down. Log (x) returns the natural logarithm of the number (base e). Max returns the highest value in the x-recorder y-recorder z-recorder. Min returns the lowest value in the x-recorder y-recorder z-recorder. Pow (xPowery) returns x to the power of y. Random () returns a random number between 0 and 1. Round (x) is rounded. Sin (x) returns the sine of the number. Sqrt (x) returns the square root of the number. Tan (x) returns the tangent of the angle.
JavaScript Global Properties
Property describes that Infinity represents a positive infinity value. NaN indicates whether a value is numeric or not. Undefined indicates an undefined value.
JavaScript global function
The function describes decodeURI () to decode an encoded URI. DecodeURIComponent () decodes an encoded URI component. EncodeURI () encodes the string as URI. EncodeURIComponent () encodes the string as a URI component. Escape () encodes the string. Eval () evaluates the JavaScript string and executes it as script code. IsFinite () checks whether a value is a finite number. IsNaN () checks whether a value is a number. Number () converts the value of the object to a number. ParseFloat () parses a string and returns a floating point number. ParseInt () parses a string and returns an integer. String () converts the value of the object to a string. Unescape () decodes the string encoded by escape ().
2. Host object
The host object is the object provided by the environment where the JS script is executed, and it is the object provided by the browser. All BOM and DOM are host objects.
3. Custom object
Objects defined by developers themselves
⑴ objects literally (create objects through JSON)
Cons: creating a lot of objects using the same interface will result in a lot of duplicate code.
⑵ factory mode.
The ① factory pattern is to put the statement to create an object in a function, create a specific object by passing in parameters, and finally return the created object.
The function createPerson () builds a Person object that contains all the necessary information based on the parameters received.
This function can be called countless times, and each time it returns an object containing two properties and a method.
② disadvantages: although the factory pattern can create multiple similar objects, it does not solve the problem of object identification, that is, how to know the type of an object.
⑶ constructor model
① disadvantages: the main problem with using constructors is that each method is created once on each instance.
② in ECMAScript, a function is an object, so every time a function is defined, an object is instantiated.
③ means that the method of instantiating multiple objects through the constructor is multiple different methods, but their internal code and functions are the same, which results in a certain waste of resources.
⑷ prototype model
In ① js, each function has a prototype property, which is a pointer to an object called a prototype object.
② uses the prototype pattern to allow all instances to share properties and methods in the prototype object, that is, it is no longer necessary to define the information of the object instance in the constructor.
③ disadvantages: omit passing initialization parameters for the constructor, resulting in all instances getting the same property value by default.
The biggest problem with the prototype pattern is caused by the nature of sharing. All properties in the prototype are shared by many instances
This kind of sharing is very appropriate for functions. For properties that contain reference types, the problem is more prominent.
④, therefore, rarely uses the prototype pattern alone.
⑸ uses a combination of constructor pattern and prototype pattern
① uses a combination of constructor pattern and prototype pattern, which is the most common way to create custom types.
The ② constructor pattern is used to define instance properties, while the prototype pattern is used to define methods and shared properties.
As a result of ③, each instance will have its own copy of the instance properties, but at the same time share the reference to the method, maximizing memory savings.
Other modes of ⑹
① dynamic prototype pattern: only when the constructor is called for the first time, the method is assigned to the corresponding property of the prototype object, and other examples are treated in the same way as the constructor pattern
② parasitic constructor mode: just encapsulates the code that creates the object, and then returns the newly created object, still calling using the new operator
③ secure constructor mode: there are no public properties, only private variables and methods, and some get/set methods to handle private variables.
At this point, the study on "what are the javascript object types" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.