Skip to content

Instantly share code, notes, and snippets.

@nuysoft
Created April 14, 2015 07:45
Show Gist options
  • Save nuysoft/e825b358103e6c984ebd to your computer and use it in GitHub Desktop.
Save nuysoft/e825b358103e6c984ebd to your computer and use it in GitHub Desktop.
函数表达式的上下文变为 window
var hooks = {
foo: function() {
console.log(this)
},
_default: function() {
console.log(this)
}
}
owner.foo() // hooks
owner['foo']() // hooks
(owner['foo'])() // hooks
(owner['foo'] || owner._default)() // window
(owner['bar'] || owner._default)() // window
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment