One, the relationship between object and function:
When I was learning JavaScript, I read about everything in JavaScript, and all the other objects in JavaScript were inherited from object, including built-in objects. Instantly feel the object bunker!
Later, and know the function, only to know that the original function is hidden behind the big boss,object is only a big bro.
Both the object and function are JS's own functions, which is a good point because it is the constructor of object, and the __proto__ property of object points to its prototype, This means that the little thing about object is inherited from it.
// true // true function(str) {Console.log (str+ "True Duang! ")};object.duang (" Your Hair "); // your hair is so duang!
Object instanceof Function //true
But then I found that "other objects in JavaScript are inherited from Object" is actually wrong , and the exact phrase should be: " Other objects in JavaScript inherit the properties and methods in Object.prototype .
Function.prototype.duang =function(str) {Console.log (str+ "Duang!) ")};
Object.duang ("Your hair.");varof ={};of.duang (Cat);
//your hair is so duang! //uncaught TypeError:of.duang is not a function (...) (anonymous function)
Function.prototype.duang=function(str) {Console.log (str+ "Duang!) ")};
Object.prototype.duang =Function.prototype.duang;
varof = {};
Of.duang (Cat); //The cat is so duang!
Second, ordinary objects and function objects:
Everything in JavaScript is object, but there are differences between objects. It is divided into function objects and ordinary objects.
function objects can create ordinary objects, ordinary objects cannot create function objects, ordinary object JS world of the lowest-level small minions, what privileges are not.
All objects created by the new function are function objects, others are ordinary objects (usually created by object) and can be judged by typeof.
function F1 () {}; typeof // "function" var New F1 (); typeof // "Object" var o2 = {}; typeof // "Object"
When a function or function expression is defined, it is created by using the function method, so the object is created.
The creation process for var f1 = function () {} or function f1 () {} is:
var New Function ();
Three, the relationship between the prototype and all aspects:
A prototype is a normal instance object of its constructor.
For any common function F1:function F1 () {};
F1.prototype is an instance object of F1 because it is not a function declaration or function expression, so it is created by new its constructor,
is created from an object, so it is a normal object.
The prototype of a function is created as follows:
var New = Temp1;
But the prototype of function is not the same, it is a functional object, because its constructor is function, it is created by function, so it is a functional object!
Its creation process is as follows:
var New = temp;
F1.prototype other relationships are as follows:
F1.prototype.constractor == = = = = = = = = = = f1.prototype.__proto__ Object.prototype
The special note here is:object.prototype.__proto__ = = = NULL;
Understanding of the prototype and __proto__ of JavaScript objects