In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article shows you how the JS prototype inheritance four-step and prototype inheritance diagram is, concise and easy to understand, definitely can make your eyes shine, through the detailed introduction of this article I hope you can gain something.
1: JS Prototype Inheritance Four Steps
//js Create and inherit simulation class//Animal, with head attribute, eat method//name attribute//Cat has name attribute, inherit Animal, catch mouse method//Step 1: Create parent class function Animal(name){this.name = name; } //Add attribute method to parent class Animal.prototype.eat = function(){ console.log(this.name + " eating... "); } //Step 2: Create subclass function Cat(name){Animal.call (this,name);} //Step 3: Cat.prototype = Object.create(Animal.prototype); //Step 4: Modify the constructor//After changing the prototype of a constructor, the code immediately following must be the constructor Cat.prototype.constructor = Cat; Cat.prototype.zhualaoshu = function(){console.log (this.name + "catch mouse"); } var mao = new Cat("cat"); mao.eat (); mao.zhualaoshu();
II: Prototype inheritance diagram
The figure below assists in understanding
Practice to consolidate understanding,
The value of__proto of the function Foo is equal to Foo.prototype, right? Can I modify the prototype of Object? Can and can't cause what can't top constructor who? Function() Who is the top-level prototype object? Object. prototypeIs the constructor member of an object a property or a method? Does the Function have__proto__, why? Is the value equal to Object.prototype? Yes, is Function.prototype; all constructors have__proto__equal to their corresponding prototype. What is a four-part inheritance that does not create a class form? Create parent class--> Create child class--> Determine inheritance relationship--> Change constructor and prototype values of constructor Function Can you modify them? Object.prototype === Object.__ Proto__? Function.prototype === Function.__ Proto__? is function F(){}; var f1 = new F();f1.__ Proto__ == Object.prototype? Not to the above content is JS prototype inheritance four-step and prototype inheritance diagram is what, you learned knowledge or skills? If you want to learn more skills or enrich your knowledge reserves, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.