美文网首页
JavaScript prototype属性

JavaScript prototype属性

作者: 歌声缓缓 | 来源:发表于2021-03-17 09:18 被阅读0次

function Hero(){

this.name="你好",

this.sayMe=function(){

alert("this is nihao") } }

Hero.prototype.name="hello";

Hero.prototype.sayMe=function(){

alert("this is hello") }

var hero =new Hero();

console.log(hero)    

console.log(hero.name)

console.log(hero.sayMe)

优先执行有变量名的,再执行__proto__

相关文章

网友评论

      本文标题:JavaScript prototype属性

      本文链接:https://www.haomeiwen.com/subject/srtlcltx.html