Home  >  Article  >  Web Front-end  >  Summary of the relationship between Object and Function in JavaScript_javascript skills

Summary of the relationship between Object and Function in JavaScript_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:45:38991browse

Function instanceof Object and Object instanceof Function are both true

1. We can think of Object as a special "class", and the "class" here is: Function

, so it can be understood as: Object = Function () {} or Object = new Function(); that is: Object is an instance of Function, so the Object prototype chain contains Function.prototype, and we get: Function.prototype.isPrototypeOf(Object) is true

2. At the same time, in js, all objects (excluding js language external objects) can be regarded as an instance of Object, Function is no exception, and Function.prototype is no exception, so Function = new Object(); Function.prototype = new Object(), so Object.prototype.isPrototypeOf(Function) and Object.prototype.isPrototypeOf(Function.prototype) are both true

3. Supplement: Function itself is also a "class". However, all "classes" are instances of Funciton, so Function instanceof Function; is true. At the same time, all objects are instances of the Object class, Object itself is also an object, and Object instanceof Object is also true. In addition, you can also think that the Funciton type is a "derived class" of the Object type, and class Function inherits class Object and is a "subclass" of class Object.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn