Home > front end >  JavaScript in the process of learning some doubts, don't understand
JavaScript in the process of learning some doubts, don't understand

Time:09-29

1. The object variables of type has a default __proto__ properties, refers to the prototype object constructor,
I declare a simple obj variable, used for... The in... Function queries its attributes, only a me about some of the custom attribute, and the like __proto__ this default property is look not to come out, is this why?
2. Statement function will automatically add a prototype property to a function, function also is a kind of objects does this show? If it is, function and what is the difference between ordinary objects and, what are the function properties, write in the function of neither as attributes or as the value of the code?

CodePudding user response:

1, __proto__ is first lookup on its own properties, and if you can't find will find along the prototype chain, you iterate over the object query is its own attributes,
2, the Object function is also right, (the function () {}) instanceof Object;//true, there is no attribute Function, not letter you can console. The log () Function. The prototype; On the background, all of its properties and methods are inherited from Object. The prototype, the Object function and the difference is that not only prototype and function Object

CodePudding user response:

__proto__ is enumerated attribute, use for... The in... Only traversal can be enumerated attribute, of which cannot be enumerated attribute is traversal

Js Function is a Function object of type, its properties and methods there are
The function fn (a, b, c) {
Return a * b + c;
}
The console. The log (fn) constructor===Function);//true that fn is to use the Function constructor creates an instance of the object
console.log(fn.name);//function, the name of the
The console. The log (fn. Length);//function receives the parameter number
The Function of objects can be commonly used method in
The apply ()
In the context of an object to another object of the method; Parameters can be passed in the form of an array,
The bind ()
Bind () method creates a new function, called a binding function. When the binding function called binding function will be introduced to bind () method to create it as this, the first parameter passed in the bind () method of the parameters of the second and later add binding function runtime parameters according to the order itself as a parameter to invoke the antiderivative of the function.
The call ()
In the context of an object to another object of the method; Can be in the form of a list of the incoming parameters,
  • Related