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/02 Report--
Editor to share with you what built-in objects in ecmascript, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
The built-in objects in ecmascript are: global object, Object object, Function object, Array object, String object, Boolean object, Number object, Math object, Date object, RegExp object, JSON object, Error object.
The operating environment of this tutorial: windows7 system, ECMAScript version 6, Dell G3 computer.
ECMAScript defines a set of built-in objects (built-in objects) that outline the definition of ECMAScript entities.
These built-in objects include:
Global objects (global object), Object objects, Function objects, Array objects, String objects, Boolean objects, Number objects, Math objects, Date objects, RegExp objects, JSON objects, and Error objects: Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError.
Global object
The only global object is established before control enters any execution environment.
Unless otherwise specified, the standard built-in properties of global objects have attributes {[[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}.
Global objects have no [[Construct]] internal attributes; global objects cannot be called as constructors with new operators.
Global objects have no [[Call]] internal properties, and global objects cannot be called as functions.
The [[Prototype]] and [[Class]] internal property values of the global object are implementation-dependent.
In addition to the properties defined by this specification, global objects can have additional host-defined properties. A global object can contain a property whose value is the global object itself; for example, in the HTML document object model, the window property of the global object is the global object itself.
Object object
Call the Object constructor as a function
When Object is called as a function, not as a constructor, it performs a type conversion.
Object ([value])
When the Object function is called with one parameter value or no argument, take the following steps:
If value is null, undefined, or unspecified, a new Object object is created and returned as if calling the standard built-in Object constructor (15.2.2.1) with the same parameters.
Returns ToObject (value).
Object constructor
When Object is part of an new expression call, it is a constructor that creates an object.
New Object ([value])
When the Object constructor is called with one parameter value or no parameters, take the following steps:
If value is provided, then if Type (value) is Object, then if value is a native ECMAScript object, instead of creating a new object, simply return value. If value is a host object, you can make it dependent on the host object by taking actions and returning the results that depend on the implementation. If Type (value) is String, it returns ToObject (value). If Type (value) is Boolean, it returns ToObject (value). If Type (value) is Number, it returns ToObject (value).
Assertion: the parameter value is not provided or its type is Null or Undefined.
Make obj a newly created native ECMAScript object.
Set the [[Prototype]] internal property of obj to the standard built-in Object prototype object (15.2.4).
Set the [[Class]] internal property of obj to "Object".
Set the [[Extensible]] internal property of obj to true.
Set all internal methods specified in obj 8.12
Return to obj.
Function object
Call the Function constructor as a function
When Function is called as a function, not as a constructor, it creates and initializes a new function object. So the function calls Function (...) Same as new Function (…) with the same parameters. The expression creates the same object.
Function (p1, p2, … , pn, body)
When p1, p2,... , pn, body call the Function function as a parameter (where n can be 0, that is, there is no "p" parameter, and body may not be provided), take the following steps:
Create and return a new function object as if to give the standard built-in constructor Function (15.3.2.1) with the same parameters. Created with an new expression.
Function constructor
When Function is called as part of an new expression, it is a constructor: it initializes the newly created object.
New Function (p1, p2, … , pn, body)
The last argument is specified as the function's body (executable code); any previous argument is specified as a formal parameter.
When p1, p2,... , pn, body as parameters to call the Function constructor (where n can be 0, that is, there is no "p" parameter, and body may not be provided), take the following steps:
Make argCount the total number of parameters passed to this function call.
Make P an empty string.
If argCount = 0, make body an empty string.
Otherwise, if argCount = 1, make body that parameter.
Otherwise, argCount > 1 makes firstArg the first parameter. Let P be ToString (firstArg). Make k 2. Repeat nextArg as the k th parameter as long as k < argCount. Let P be the previous P value, the string "," (a comma), the result of concatenating ToString (nextArg). K increases by 1. Make body the k th parameter.
Make body ToString (body).
If P cannot be resolved to a FormalParameterListopt, a SyntaxError exception is thrown.
If body cannot be resolved to FunctionBody, a SyntaxError exception is thrown.
If body is strict mode code (see 10.1.1), make strict true, otherwise make strict false.
If strict is true, apply 13.1 any exceptions that are specified.
Returns a newly created function object that is created as specified by 13.2-courier P as FormalParameterList,body as FunctionBody, global environment as Scope parameter, and strict as strict mode flag.
Each function automatically creates a prototype attribute to support the possibility that the function will be used as a constructor.
Specifying a parameter for each parameter is allowed, but not necessary. For example, the following three expressions produce the same result:
New Function ("a", "b", "c", "return a+b+c") new Function ("a _ r, c", "return a+b+c") new Function ("a _ r", "c", "return a+b+c")
Array object
An array is an ordered collection of values, each value in the array is called an element, and each element has a numerical position in the array, called an index, which starts at 0 and increases in turn. In JavaScript, you can define arrays using the Array object. In addition, various properties and methods related to arrays are provided in the Array object.
The syntax format for creating an Array object is as follows:
Var arr = new Array (values); var arr = Array (values)
Where values is a list of elements in the array, separated by commas.
String object
The String object is used to process strings, which provides a number of methods for manipulating strings, as well as some properties.
The syntax format for creating a String object is as follows:
Var val = new String (value); var val = String (value)
Where the parameter value is the string or string object to be created.
In JavaScript, strings and string objects can be converted freely, so whether you are creating a string object or directly declaring a variable of a string type, you can directly use the methods and properties provided in the string object.
Boolean object
A JavaScript Boolean can have one of two values: true or false.
Call the Boolean constructor as a function
When Boolean is called as a function, not as a constructor, it performs a type conversion.
Boolean (value)
Returns the Boolean value (non-Boolean object) calculated by ToBoolean (value).
Boolean constructor
When Boolean is called as part of an new expression, it is a constructor: it initializes the newly created object.
New Boolean (value)
The [[Prototype]] internal property of the newly constructed object is set to the original Boolean prototype object, which is the initial value of Boolean.prototype (15.6.3.1).
The [[Class]] internal property of the newly constructed object is set to "Boolean".
The [[PrimitiveValue]] internal property of the newly constructed object is set to ToBoolean (value).
The [[Extensible]] internal property of the newly constructed object is set to true.
Number object
In JavaScript, you can use decimal, hexadecimal, or octal representations to represent integers or floating point numbers. Unlike other programming languages, numbers in JavaScript do not distinguish between integers and floating-point numbers. They are represented by the 64-bit floating-point format of the IEEE754 standard (binary floating-point arithmetic standard). The maximum value (Number.MAX_VALUE) is ±1.7976931348623157e+308 and the minimum value (Number.MIN_VALUE) is ±5e-324. The sample code is as follows:
Var x = 123; / / Integer var y = 3.14; / / floating point var z = 0xff; / / hexadecimal number: 255
For larger numbers, you can use an exponential representation, for example, 6.02e+23 equals 6.02 x 10 °³. The sample code is as follows:
Var x = 1.57e4; / equals 15700var y = 4.25eq6; / / equals 4250000var z = 4.25eMur6; / / equals 0.00000425
Tip: the largest integer that can be represented in JavaScript is 2 °³- 1, that is, 9007199254740991, and the smallest integer that can be represented is-(2 °³- 1), that is,-9007199254740991.
In addition to using decimal to represent numbers, you can also use octal or hexadecimal notation, where octal representation uses 0 as the prefix and hexadecimal representation uses 0x as the prefix. The sample code is as follows:
Var a = 0377; / equals 255var b = 0123; / equals 83var c = 0xff; / / equals 255var d = 0xb4; / / equals 180
Note: integers can be represented in decimal, hexadecimal, and octal representations, and floating-point numbers in decimal or exponential representations.
Math object
Math is a built-in object in JavaScript, which provides some constant values and functions commonly used in mathematics to achieve some common mathematical calculations, such as calculating averages, finding absolute values, rounding and so on.
Unlike the previously introduced objects (such as Number object, String object, Array object, etc.), calling properties and methods in a Math object does not require the use of the new operator to create it in advance, but simply calls Math as an object, for example:
Var pi_val = Math.PI; / / the value of π in mathematics: 3.141592653589793var abs_val = Math.sin (- 5.35); / /-the absolute value of 5.35
The Math object is a single object that has some named attributes, some of which are functions.
The value of the [[Prototype]] internal property of the Math object is the standard built-in Object prototype object (15.2.4). The value of the [[Class]] internal property of the Math object is "Math".
The Math object has no [[Construct]] internal property; the Math object cannot be called by the new operator as a constructor.
The Math object has no [[Call]] internal property; the Math object cannot be called as a function.
Date object
The Date object is a built-in object in JavaScript that gives you access to the time of the computer system. In addition, the Date object provides a variety of methods for managing, manipulating, and formatting time / date.
RegExp (regular expression) object
A RegExp object contains a regular expression and associated flags.
The format and functionality of regular expressions are modelled on the regular expression facility of the Perl 5 programming language.
JavaScript string is the most frequently used data type in programming, and it is necessary to operate on a string in many places, such as judging whether a string is a legal E-mail address, intercepting a specified part from a string, and so on.
Regular expression is a kind of logical formula used to match strings or special characters. the so-called logical formula is composed of some specific characters to represent some rules of special strings, which can express the filtering logic of string data.
In JavaScript, you need to use regular expressions with the help of RegExp objects, and there are two ways to create RegExp objects, as follows:
Var patt = new RegExp (pattern, modifiers); var patt = / pattern/modifiers
The parameters are described as follows:
Pattern: regular expressions, regular expressions defined according to the syntax of regular expressions
Modifiers: modifier that sets the matching pattern of the string.
JSON object
The JSON object is a single object that contains two functions, parse and stringify, that are used to parse and construct JSON text. The exchange format of JSON data is described in RFC4627. . The JSON exchange format in this specification uses what is described in RFC4627, with the exception of the following two points:
The top-level JSONText production in ECMAScript JSON grammar is made up of JSONValue, not JSONObject or JSONArray made from the middle limit of RFC4627.
Confirm the implementation of JSON.parse and JSON.stringify, which must accurately support the interchange format described in this specification and do not allow deletion or extension of the format. This differs from RFC4627 in that it allows JSON parsers to accept non-JSON formats and extensions.
The value of the internal property [[Prototype]] of the JSON object is the standard built-in Object prototype object (15.2.4). The value of the internal attribute [[Class]] is "JSON". The value of the internal property [[Extensible]] is set to true.
The JSON object has no internal attribute [[Construct]]; the JSON object cannot be used as a constructor to use the new operator.
The JSON object has no internal attribute [[Call]]; the JSON object cannot be called as a function.
Error object
An instance of the Error object is thrown as an exception when it encounters an error at run time. The Error object can also be used as the base object for user-defined exception classes.
The above is all the content of the article "what are the built-in objects in ecmascript"? thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow 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.