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()
both lines of code output are:
xiaoming
xiaohong
so what"s the difference between them? Where is the variable let name stored?
does the first code snippet make the output different because of the closure?