Basic data types
The basic data type is the lowest level of the JS language implementation.
Simple numeric type: There are undefined, Null, Boolean, number, and string. Note that the English words in the description are only indexed according to the type name, not specifically JS's global objects n An, Boolean, number, string, and so on, their conceptual differences are relatively large.
Object: A collection of unordered properties that have values of a simple numeric type, an object, or a function. Ditto, the object here is not specifically the global object.
Function: A function is an object, the implementation of the internal property [[Class]] value of "function", indicating that it is a function type, in addition to the object's internal property methods, there are [[construct]], [[Call]], [[Scope]], and so on internal properties. Functions as function calls are not the same processing mechanisms as constructors (which create instance objects using the New keyword), and internal methods [[construct]] are used to implement the logic as constructors, and method [[call]] implements logic as function calls. Ditto, the functions here do not refer specifically to the Global object function.
Functions can be considered as object-oriented language classes in the prototype language of JS, which can be used to construct object instances. Since functions can be thought of as classes, each function can be viewed as an extended data type.
Built-in data types (built-in objects)
Function: The user interface of the functional type.
Object: The user interface for the types of objects.
Boolean, number, String: An object wrapper for these three simple numeric types, and the object wrapper is somewhat conceptually similar to the Box/unbox in C #.
Date, Array, REGEXP: You can think of them as several built-in extended data types.
First, function, object, Boolean, number, String, Date, Array, RegExp, and so on are all built-in objects in the JavaScript language, and they can all be considered as derived types of functions, such as number The instanceof function is True,number instanceof object is true. In this sense, they can be equated with user-defined functions.
Second, they can represent a data type, by the JS engine with native code or built-in JS codes to implement, is exposed to developers of these built-in data types to operate the interface. In this sense, they are an abstract concept that hides the specific implementation mechanism behind it.
In every word that mentions number, function, etc., you should quickly instantiate them in your mind as one of the above two situations.
Data type Implementation Model description
build-in * * * * * data structure: refers to JS internal for the implementation of the type of database structure, these structures we basically can not directly operate.
build-in * * * * object: Refers to JS built-in number, String, Boolean and other objects, this is the internal implementation of JS data types exposed to developers to use the interface.
build-in * * * * constructor: Refers to JS built-in some constructors, used to construct the corresponding type of object instances. They are packaged as function objects exposed, such as we can access these function objects using the following methods:
//Passed in FF2.0, IE7, Opera9.25, Safari3.0.4
//access the build-in number constructor
var number = new Number(123);
var numConstructor1 = number.constructor; //or
var numConstructor2 = new Object(123).constructor;
//both numConstructor1 and numConstructor2 are the build-in Number constructor
numConstructor1 == numConstructor2 //result: true
//access the build-in object constructor
var objConstructor1 = {}.constructor; //or
var objConstructor2 = new Object().constructor;
//both objConstructor1 and objConstructor2 are the build-in Object constructor
objConstructor1==objConstructor2 //result: true
In concrete implementations, there may also be an association between the landscape in the above illustration, for example, for build-in data structure and constructor,function, Date, Array, RegExp, and so on, to inherit the structure of the object. But this is a matter of concrete implementation.
About the object of simple numeric types
This is a fine place to describe the three simple numeric types for Boolean, string, and number, which is illustrated by the example.
JS Specification requirements: Use the var num1=123; Such code, directly returns the basic data type, that is, the returned object is not derived from the number and type object, with Num1 instanceof Object test is False ; Use the new keyword to return the number type, such as var num2=new number (123); Num2 instanceof number is true.
Use number as a function call, and the return result is converted to a simple numeric type. Here is the test code:
//Passed in FF2.0, IE7, Opera9.25, Safari3.0.4
var num1 = new Number(123); //num1 derived from Number & Object
num1 instanceof Number //result: true
num1 instanceof Object //result: true
//convert the num1 from Number type to primitive type, so it's no longer an instance of Number or Object
num1 = Number(num1);
num1 instanceof Number //result: false
num1 instanceof Object //result: false
var num2 = 123; //num2 is a primitive type
num2 instanceof Number //result: false
num2 instanceof Object //result: false
Although we got a simple numeric type, it still looks like a JS object, with object and all of the properties and methods of the corresponding type, there is no difference in use, the only difference is the instanceof test results.
Prototype inheritance
Prototype