发布于2021-03-17 05:19 阅读(1748) 评论(0) 点赞(22) 收藏(0)
温故而知新,前面的知识多多少少遗忘了些,复习后写篇博客总结一下~
通过下图,我们先有一个大概的认识~
上图代码~
function Student(name,age){ //构造函数
this.name=name;
this.age=age;
}
Student.prototype.say=function(){ //设置公共属性
console.log("hello");
}
var tom = new Student("tom",19); //创建实例
var mary = new Student("mary",19);
tom.say();
mary.say();
console.log(tom);
console.log(mary);
接上面栗子~
tom.watch="CASIO";
mary.skirt="pink";
console.log(tom.watch); //CASIO
console.log(mary.skirt); //pink
Student.prototype.birthday="2000/1/1";
console.log(tom.birthday) //2000/1/1
console.log(mary.birthday) //2000/1/1
function Hero(){
this.name="Spider man"
}
Hero.prototype.name="Iron Man";
var hero= new Hero();
console.log(hero.name); //Super man
delete hero.name;
console.log(hero.name); //Iron man
delete Hero.prototype.name;
console.log(hero.name); //undefined
我们还是看图来理解
图中红色的链路就是所谓的原型链~
prototype、_ _ proto _ _和constructor的三角关系
通过上图可以总结得出:
console.log(tom.__proto__===Student.prototype) //true
console.log(tom.constructor===Student) //true
console.log(Student.prototype.constructor===Student) //true
先总结到这儿了~
如果对你有帮助,点个赞支持一下吧~
本文借鉴了以下文章~
https://blog.csdn.net/cc18868876837/article/details/81211729
原文链接:https://blog.csdn.net/weixin_44410783/article/details/114786706
作者:92wwhehjw
链接:http://www.qianduanheidong.com/blog/article/39143/c2c2d0238c028681b47e/
来源:前端黑洞网
任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任
昵称:
评论内容:(最多支持255个字符)
---无人问津也好,技不如人也罢,你都要试着安静下来,去做自己该做的事,而不是让内心的烦躁、焦虑,坏掉你本来就不多的热情和定力
Copyright © 2018-2021 前端黑洞网 All Rights Reserved 版权所有,并保留所有权利。 京ICP备18063182号-3
投诉与举报,广告合作请联系vgs_info@163.com或QQ3083709327
免责声明:网站文章均由用户上传,仅供读者学习交流使用,禁止用做商业用途。若文章涉及色情,反动,侵权等违法信息,请向我们举报,一经核实我们会立即删除!