当前位置:网站首页>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__)
边栏推荐
- Research Report on market demand and investment planning for the development of China's office chair industry, 2022-2028
- Internet hospital his management platform source code, online consultation, appointment registration smart hospital applet source code
- i++与++i的区别:通俗易懂的讲述他们的区别
- [combinatorics] recursive equation (case where the non-homogeneous part is exponential | example where the non-homogeneous part is exponential)
- Codeforces Round #803 (Div. 2) C. 3SUM Closure
- MySQL grouping query
- TCP congestion control details | 3 design space
- AcWing 271. Teacher Yang's photographic arrangement [multidimensional DP]
- [set theory] order relation: summary (partial order relation | partial order set | comparable | strictly less than | covering | hasto | total order relation | quasi order relation | partial order rela
- 圖像24比特深度轉8比特深度
猜你喜欢
Cloud primordial weekly | CNCF released the 2021 cloud primordial development status report, which was released on istio 1.13
1146_ SiCp learning notes_ exponentiation
网格图中递增路径的数目[dfs逆向路径+记忆dfs]
[combinatorics] recursive equation (summary of the solution process of recursive equation | homogeneous | double root | non-homogeneous | characteristic root is 1 | exponential form | the bottom is th
Interviewer: why is the value nil not equal to nil?
(9) Opencv Canny edge detection
Leetcode Valentine's Day Special - looking for a single dog
Research Report on market demand and investment planning for the development of China's office chair industry, 2022-2028
Research on Swift
聊聊支付流程的設計與實現邏輯
随机推荐
一入“远程”终不悔,几人欢喜几人愁。| 社区征文
Getting started with deops
[Tongxin UOS] scanner device management driver installation
Automata and automatic line of non-standard design
Line by line explanation of yolox source code of anchor free series network (6) -- mixup data enhancement
Redis core technology and practice - learning notes (11): why not just string
(9) Opencv Canny edge detection
[combinatorics] recursive equation (the non-homogeneous part is an exponential function and the bottom is the characteristic root | example of finding a special solution)
Redis core technology and practice - learning notes (VIII) sentinel cluster: sentinel hung up
Classroom attendance system based on face recognition tkinter+openpyxl+face_ recognition
Kotlin's collaboration: Context
Win32: dump file analysis of heap corruption
Line by line explanation of yolox source code of anchor free series network (5) -- mosaic data enhancement and mathematical understanding
STM32 realizes 74HC595 control
A. Berland Poker & 1000 [simple mathematical thinking]
Servlet specification Part II
Graduation summary
[Yu Yue education] family education SPOC class 2 reference materials of Shanghai Normal University
STM32实现74HC595控制
[vscode] convert tabs to spaces