Created
May 19, 2018 17:27
-
-
Save khg0712/76567fcf48d20041219c1cf9514446f9 to your computer and use it in GitHub Desktop.
내부 함수에서 this를 변수에 저장하는 예시
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = 10;//전역 변수 a 생성 | |
var object = { | |
a: 1, | |
func1: function() { | |
var that = this;//that 변수에 this 저장 | |
this.a += 1; | |
console.log('func1: ' + this.a); | |
var func2 = function () { | |
that.a += 1; | |
console.log('func2: ' + that.a); | |
var func3 = function () { | |
that.a += 1; | |
console.log('func3: ' + that.a); | |
} | |
func3(); | |
} | |
func2(); | |
} | |
} | |
object.func1(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment