functionStudent(n){letname=n;this.say=function(){console.log(name)}}letxiaoming=newStudent('xiaoming')letxiaohong=newStudent('xiaohong')xiaoming.say()xiaohong.say()functionStudent(n){this.name=n;this.say=function(){console.log(this.name)}}letxiaoming=newStudent('xiaoming')letxiaohong=newStudent('xiaohong')xiaoming.say()xiaohong.say()这两行代码输出都是:xiaomingxiaohong那么他们的区别是什么?letname这个变量存储在哪?第一个代码段是因为闭包才使得输出不同吗?
添加回答
举报
0/150
提交
取消