JS provides some built-in objects, functions, and constructors for programming, such as math, parseint, object, array, and so on. These are visible and can be used in programming. For example, I can new Object or new Array.
Some are not visible, and these objects can only be provided by the engine in a particular situation. These types of objects are often reduced to a number of functions. Listed below are some
I. Type of Arguments
The Arguments type cannot be manually created by the programmer, that is, you cannot create a new Arguments (). It has and has only one object arguments
Copy Code code as follows:
function func () {
Console.log (Arguments[0])//1
Console.log (Arguments.length)//3
}
Func (1, 2, 3)
The arguments object is created at the time of the function call and is visible and used only within the function. You can see that arguments is very much like an array, you can index elements and the length property. But it is not array, it has no array of some methods such as push, pop and so on. Arguments is defined in ES5 10.6.
Second, the function returned by BIND is very special
Bind is a new method that ES5 gives Function.prototype, which is called directly on function like call/apply. It returns a function that specifies the context and parameters.
Copy Code code as follows:
function func (age) {
Console.log (' name: ' + THIS.name + ', career: ' + age ')
}
var person = {name: ' John McCarthy '}
var f1 = func.bind (person, ' computer scientist ')
F1 ()//Name:john McCarthy, career:computer scientist
You can see that the returned function F1 the same as the normal function using parentheses to execute the call. Everything's fine, but the code below will surprise you.
Copy Code code as follows:
function func (age) {
Console.log (' name: ' + THIS.name + ', career: ' + age ')
}
var person = {name: ' John McCarthy '}
var f1 = func.bind (person, ' computer scientist ')
Console.log (f1.prototype)//undefined
Compared with the above code, the last sentence is different, does not execute F1 (), but print out f1.prototype, found to be undefined.
Is it strange? Does each function have a prototype attribute, which is used to implement the prototype inheritance Oh. Indeed, the function returned by bind is rather special, and it has no prototype. This special function is created by the JS engine, and the client programmer is not able to use the function declaration or the direct amount of the function.
This point is clearly indicated in the specification ES5 15.3.4.5