Var name='111'
Var a={
Name: '222'
Say: the function () {
The console. The log (enclosing name)
}
}
Var b={
Name: '333'
Say: function (fun) {
Fun ()
}
}
B. say (a. say)
</script>
Or
<script>
Var name='111'
Var obj={
Name: '222'
Say: the function () {
(function () {
The console. The log (enclosing name)
} ())
}
}
Obj. Say ()
</script>
Why is the console window is this?
CodePudding user response:
This generally refers to the object, of the calls to functions that contain this here this should not mean b. say methods or contain anonymous functions ()? But these are not objectsCodePudding user response:
Inside the method, this is a special variable, it always point to the current object, you this here refers to the object ahttps://shuxhan.com/20201104-javascript-function/#1.this
CodePudding user response:
Want to method invokes the object's properties, must go through thisCodePudding user response: