This article mainly introduces some information about the understanding of the JS prototype chain. If you need a friend, you can refer to the prototype chain to understand it. There are also a lot of online materials, when I can't sleep at night, I always like to read articles about prototype chains and closures on the
// TrueArray. _ proto _ =Function. prototype// TrueRegExp. _ proto _ = Function. prototype// TrueError. _ proto _ =Function. prototype// TrueDate. _ proto _ =Function. prototype// True
It indicates that Number and so on are all constructors, which are actually an object of Function. That is, it is equivalent to var Nu
This article mainly introduces the javascript prototype chain and inheritance related information. If you need it, you can refer to the js prototype chain and inheritance, which is the focus of js, therefore, we will give a detailed explanation through the following three examples.
First, define an object obj. The
(test.name)//"a";
The name attribute is not set for test, but why is there a value?
This is prototype's credit. The name object in the prototype attribute in uw3c is inherited to the property of the test object after uw3c is constructed by the new constructor. Next, let's see:
var name = "js";function jb51(name){alert(this.name);//"css"}jb51.prototype.name = "css";var test = new jb51();test()
Why is the
It is found that most people use Array. prototype. slice. call (argments, 0) and never understand what this sentence is. I reviewed the slice () method yesterday, and then referred to Function. call (thisArg [, arg1 [, arg2 [,...]), I still don't know (my mind is slow: | ).
Writing front
In js, we often see Array. prototype. slice. call (arguments, 0), of course
JavaScript inheritance and standard OOP inheritance are very different, JavaScript inheritance is the use of prototype chain technology, each class will be "member variable" and "member function" on the prototype, js++ have superclass link it up, that is C.prototype.superclass = C.superclass = P.prototype;When var C = new C (), c.__proto__ = C.prototype;When C ac
Deep understanding of JS prototype and prototype chain, and deep understanding of js prototype
PrototypeIt is a concept that is hard to understand in JavaScript. There are also many prototype-related attributes, the object has the
Talking about the JS prototype object and prototype chain, talking about the js prototype
In Javascript, all objects are objects, but objects are also different. They can be divided into two types: common objects and Function objects ).
In general, the objects generated thro
One, instanceof:instanceof detects if there is a prototype prototype on the right side of the __PROTO__ prototype chain on the left. I've been in two previous articles[JS Master's Road] the basic characteristics and advantages and disadvantages of the constructor function[JS
the diagram, so:Console.log (Obj1.showusername = = = Obj2.showusername); FalseNow, you should be able to understand that by writing properties and methods on the prototype object (prototype) of the constructor, it is possible to implement the sharing principle of multiple instance properties and methods.What is a prototype chain?In the preceding, I have said tha
One, instanceof:instanceof detects if there is a prototype prototype on the right side of the __PROTO__ prototype chain on the left. I've been in two previous articles[JS Master's Road] the basic characteristics and advantages and disadvantages of the constructor function[JS
not found, the value is Undefined.console.log (Obj1.showusername ()); Ghostwuconsole.log (Obj2.showusername ()); Weizhuang There is no showusername this method on the obj1,obj2, so it will follow the __proto__ Find the Showusername method on the Createobj.prototype prototype object if the Showusername on the Createobj.prototype prototype object is commented out, then Obj1.showusername and Obj2.showusern AM
) __proto__ are Function.prototype, who is Function.prototype __proto__?I believe I have heard that the function in JavaScript is also a class citizen, where can it be manifested? As follows// trueThis means that all constructors are also a common JS object, which can add/remove attributes to the constructor, and so on. It also inherits all the methods on Object.prototype: ToString, ValueOf, hasOwnProperty, and so on.Who was the last Object.prototype
For the rewrite of prototype prototype objects, we can use the following two ways:
Add the attributes you want to add to the prototype object using the most primitive syntax
function= "Tom"="Doctor"; Person.prototype.sayname=function() { alert (this. name);} var New Person (); Person1.sayname (); // Tom2. Use a simple
JS prototype chain details and sample code, js prototype sample code
Preface
On segmentfault, you can see the following question:
var F = function(){};Object.prototype.a = function(){};Function.prototype.b = function(){};var f = new F();
Q: Can I obtain a and B from f? What is the principle?
At first glance, it was a b
How to Understand JS prototype chain and JS prototype chain
Before talking about the prototype chain, we must first understand the relationship between user-defined functions and functions. What are the links between constructors, prototypes, and instances? In fact, all func
function: ' +typeof function); functionConsole.log (' typeof O1: ' +typeof O1); ObjectConsole.log (' typeof O2: ' +typeof O2); ObjectConsole.log (' typeof F1: ' +typeof F1); functionConsole.log (' typeof F2: ' +typeof F2); functionConsole.log (' typeof F3: ' +typeof F3); function
Usually we think O1, O2 is the object, namely the ordinary object; F1, F2, and F3 are functions.
But in fact functions are objects, which are constructed by function,
F3 this is the same way the object
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.