当前位置:网站首页>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__)


边栏推荐
- Interviewer: why is the value nil not equal to nil?
- How to deploy applications on kubernetes cluster
- PHP MySQL order by keyword
- 【统信UOS】扫描仪设备管理驱动安装
- Redis core technology and practice - learning notes (VIII) sentinel cluster: sentinel hung up
- WebView module manages the application window interface to realize the logical control and management operation of multiple windows (Part 1)
- 聊聊支付流程的设计与实现逻辑
- PHP MySQL reads data
- Introduction to SolidWorks gear design software tool geartrax
- Codeforces Round #803 (Div. 2) C. 3SUM Closure
猜你喜欢

AcWing 271. 杨老师的照相排列【多维DP】

TCP拥塞控制详解 | 3. 设计空间

TCP congestion control details | 3 design space

聊聊支付流程的設計與實現邏輯

Talk about the design and implementation logic of payment process

The second largest gay dating website in the world was exposed, and the status of programmers in 2022

Leetcode Valentine's Day Special - looking for a single dog

Leetcode 669 pruning binary search tree -- recursive method and iterative method

Records of long objects and long judgments in the stream of list

Redis core technology and practice - learning notes (VI) how to achieve data consistency between master and slave Libraries
随机推荐
基于人脸识别的课堂考勤系统 tkinter+openpyxl+face_recognition
The third day of writing C language by Yabo people
[tutorial] build your first application on coreos
Tensorboard quick start (pytoch uses tensorboard)
A. Odd Selection【BruteForce】
Redis on local access server
The gbase 8A database does not support the DB2 function value (column_name, 0) cluster syntax
Research Report on investment trends and development planning of China's thermal insulation material industry, 2022-2028
[combinatorics] recursive equation (four cases where the non-homogeneous part of a linear non-homogeneous recursive equation with constant coefficients is the general solution of the combination of po
Website with JS doesn't work in IE9 until the Developer Tools is activated
[combinatorics] generating function (commutative property | derivative property | integral property)
As soon as we enter "remote", we will never regret, and several people will be happy and several people will be sad| Community essay solicitation
数学公式(测试)
Kotlin的協程:上下文
Kotlin's collaboration: Context
Assembly for unloading Loadfrom() loaded assembly - unloading the assembly loaded with assembly LoadFrom()
How to enforce parameters in PowerShell- How do I make parameters mandatory in PowerShell?
OpenSSL的SSL/BIO_get_fd
Distributed task distribution framework gearman
[linux]centos 7 reports an error when installing MySQL "no package MySQL server available" no package ZABBIX server MySQL available