function Persion(name){
this.name = name;
this.sayHi = function(){
//var that = this; 해결방법
//새로운 스코프
setTimeout(function(){
console.log('hello my name is ' + this.name) //that.name으로 변경
},1000)
}
}
const person = new Person('bob');
person.sayHi()
실행시 익명함수의 this가 글로벌 객체(윈도우객체)를 가르키게되어 아무것도 표시하지 않는다.
fat arrow function을 사용하면 이런 문제를 방지할수있다.
setTimeout(() => {
console.log('hello my name is ' + this.name)
}
참조 : 유튜브 https://www.youtube.com/watch?v=O0tGVx3QQYE
2017년 5월 17일 수요일
피드 구독하기:
댓글 (Atom)
-
운영체제를 다시 설치할때 보통 윈도우 인스톨러인가 UUI ? 뭐 정확히는몰라도 여러가지 프로그램을 사용하는데 이번에 rufus 라는 프로그램을 접하게 되었다. rufus 오류 미디어를 열 수 없습니다. 이런 오류를 뿜으면서 자꾸 안된다. ...
-
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2) Posted on 22/04/2015 by Admin | Leave ...
-
타입스크립트 관련 이유없이 빨간줄이간다. 설정과 관련이 있는데 tsconfig.json이나 systemjs.config.js 에서 experimentalDecorators: true 설정을넣어줘도 안없어진다. 비쥬얼 스튜디오 코드 설...
댓글 없음:
댓글 쓰기