// (function(){
// function Tune(artist, song){
// this.artist = artist;
// this.song = song;
// }
// Tune.prototype.play = function(){
// console.log(this.artist + ' 演唱了这首: ' + this.song)
// }
// var t1 = new Tune('zhou', '夜曲');
// t1.play();
// var t2 = new Tune('jj', '江南');
// t2.play()
// var sf = new Tune('sf', '')
// sf.play = function(){
// if(!this.song) {
// console.log(this.artist + ' 他啥也不会')
// }
// }
// sf.play()
// })()
// 1. 使用call方法实现对象继承
// 参考链接: https://blog.csdn.net/jyoxun/article/details/84243147
function Animal(name){
this.name = name;
this.showName = function(){
alert(this.name)
}
}
function Cat(name){
Animal.call(this, name)
}
Cat.prototype = new Animal(); // 这一招实现了继承666
var cat = new Cat('miao');
console.log(cat)
// cat.showName()
console.log(cat instanceof Animal)
console.log(cat instanceof Cat)
// 每个js对象在(null除外),在创建的时候都会关联另一个对象,这个对象就是我们所说的原型,每一个对象都会从原型继承属性。
// 原型链:https://blog.csdn.net/weixin_39998541/article/details/110904411
function Animal(){
this.species = '动物';
}
function Dog(name){
this.name = name
}
// Dog.prototype = new Animal();
function Samo(){
this.color = 'white';
this.size = 'big'
}
Samo.prototype = new Dog('Samo')
var dog = new Samo()
console.log(dog)
<html>
<body>
<div>test</div>
</body>
</html>