Skip to content

Instantly share code, notes, and snippets.

@MisaOgura
Last active October 22, 2017 18:55
Show Gist options
  • Save MisaOgura/4f0d040821cf9a410672f21367149bea to your computer and use it in GitHub Desktop.
Save MisaOgura/4f0d040821cf9a410672f21367149bea to your computer and use it in GitHub Desktop.
// scope chain: { name: undefined }
var name = 'John'
// scope chain: { name: 'John' }
function greet (name) {
// [[scope]]: { name: 'John' }
// scope chain: { name: 'John', outerScope: { name: 'John' } }
return (function () {
// [[scope]]: { name: 'John', outerScope: { name: 'John' } }
// scope chain: { name: 'John', outerScope: { name: 'Sam' } }
console.log('Hello ' + name)
})
}
var sayHello = greet(name)
name = 'Sam'
// scope chain: { name: 'Sam' }
sayHello() // 'Hello John'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment