当前位置:网站首页>Prototype inheritance..
Prototype inheritance..
2022-07-03 17:57:00 【Yellow sauce!】
<script>
// Inherit : for example , Fengjianweiyou 1000 ten thousand , A hundred years later , His son inherited 10 Yuan
// Be careful : Inheritance is to inherit the same attributes ( Something in common ), Inheritance between classes
function Dog(name, age){
this.name = name
this.age = age
}
Dog.prototype.rg = function(){
console.log(' Like to wander around !')
}
function Tugou(name, age){
this.name = name
this.age = age
}
// Inheritance is required
// Prototype inheritance , It is conducive to the inheritance of the search rules of the prototype chain
//Tugou.prototype It's an object , Can you re assign values to objects , Sure
Tugou.prototype = Dog.prototype
// stay Tugou A method is set on the prototype
Tugou.prototype.eat = function(){
console.log(' Like to eat all kinds of things ')
}
console.log(Dog.prototype)
//Tugou.prototype.constructor = Tugou
let t1 = new Tugou(' Little black ', 2)
t1.rg()
// let t2 = new Dog(' Xiaohong ',3)
console.log(Tugou.prototype)
console.log(t1.__proto__)
</script>
// Inherit : for example , Fengjianweiyou 1000 ten thousand , A hundred years later , His son inherited 10 Yuan
// Be careful : Inheritance is to inherit the same attributes ( Something in common ), Inheritance between classes
function Dog(name, age) {
// The code in the constructor body can also inherit
this.name = name
this.age = age
}
Dog.prototype.rg = function () {
console.log(' Like to wander around !')
}
function Tugou(sex) {
// this.name = name
// this.age = age
this.sex = sex
}
// Inheritance is required
// Prototype inheritance , It is conducive to the inheritance of the search rules of the prototype chain
//Tugou.prototype It's an object , Can you re assign values to objects , Sure
//Tugou The prototype object of is equal to Dog Instantiation object of constructor
Tugou.prototype = new Dog(' Little black ', 2)
Tugou.prototype.eat = function(){
console.log(' You know how to eat ')
}
//Tugou.prototype.constructor = Tugou
let t1 = new Tugou(' Male ')
t1.rg()
// console.log(Dog.prototype)
t1.eat()
console.log(t1)
console.log(t1.name)
// console.log(t1.__proto__)


边栏推荐
- [tutorial] build your first application on coreos
- The second largest gay dating website in the world was exposed, and the status of programmers in 2022
- [combinatorics] generating function (commutative property | derivative property | integral property)
- Redis core technology and practice - learning notes (VIII) sentinel cluster: sentinel hung up
- [combinatorics] generating function (summation property)
- WEB-UI自动化测试-最全元素定位方法
- 聊聊支付流程的設計與實現邏輯
- i++与++i的区别:通俗易懂的讲述他们的区别
- Redis core technology and practice - learning notes (VI) how to achieve data consistency between master and slave Libraries
- Global and Chinese pediatric palliative care drug market development research and investment planning recommendations report 2022-2028
猜你喜欢

The third day of writing C language by Yabo people

On Data Mining

MySQL has been stopped in the configuration interface during installation

Talk about the design and implementation logic of payment process

Investigation on the operation prospect of the global and Chinese Anti enkephalinase market and analysis report on the investment strategy of the 14th five year plan 2022-2028

STM32 realizes 74HC595 control

Research Report on competitive strategy Outlook Analysis and investment strategic planning of China's smart home equipment industry, 2022-2028

Redis core technology and practice - learning notes (VIII) sentinel cluster: sentinel hung up

How to deploy applications on kubernetes cluster

Leetcode 669 pruning binary search tree -- recursive method and iterative method
随机推荐
WebView module manages the application window interface to realize the logical control and management operation of multiple windows (Part 1)
Implementation of Tetris in C language
Leetcode 538 converts binary search tree into cumulative tree -- recursive method and iterative method
Analyse ArrayList 3: suppression d'éléments
Leetcode Valentine's Day Special - looking for a single dog
ES6类的继承
Mathematical formula (test)
[combinatorics] recursive equation (the non-homogeneous part is an exponential function and the bottom is the characteristic root | example of finding a special solution)
远程办公工具分享|社区征文
QT learning diary 9 - dialog box
Vs2013 has blocked the installer, and ie10 needs to be installed
Research on Swift
Introduction to PHP MySQL
Postfix 技巧和故障排除命令
How to purchase Google colab members in China
TCP拥塞控制详解 | 3. 设计空间
模块九作业
Redis core technology and practice - learning notes (VI) how to achieve data consistency between master and slave Libraries
1147_ Makefile learning_ Target files and dependent files in makefile
解决Zabbix用snmp监控网络流量不准的问题