为了账号安全,请及时绑定邮箱和手机立即绑定

这种结构可以叫闭包吗?

这种结构可以叫闭包吗?

婷婷同学_ 2019-03-04 17:01:35
  function Student(n) {    let name = n;    this.say = function () {      console.log(name)     }   }  let xiaoming = new Student('xiaoming')  let xiaohong = new Student('xiaohong')   xiaoming.say()   xiaohong.say()  function Student(n) {    this.name = n;    this.say = function () {      console.log(this.name)     }   }  let xiaoming = new Student('xiaoming')  let xiaohong = new Student('xiaohong')   xiaoming.say()   xiaohong.say()这两行代码输出都是:xiaomingxiaohong那么他们的区别是什么? let name 这个变量存储在哪?第一个代码段是因为闭包才使得输出不同吗?
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 444 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号