首页 新闻 会员 周边

请问当前对象添加方法跟原型上面添加方法有什么不一样,哪一种比较好

0
悬赏园豆:20 [已关闭问题] 关闭于 2016-08-22 17:01

<script>
function Person()
{
//通过原型添加的方法
Person.prototype.say=function()
{
alert("hello");
}

//当前对象添加的方法
this.say=function()
{
alert("hello1");
}
}

//这两者有什么不一样,这里都可以调用
var p=new Person(); 
p.say(); 
</script>

渣男$的主页 渣男$ | 初学一级 | 园豆:158
提问于:2016-08-19 17:29
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册