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 ...
-
국비지원 프론트엔드 과정을 선택한건 정말 잘못된 선택이었다. 해당과정에서 배운건 html , javascript, css, php 프로젝트들... 추가적으로 angularjs , spa 이런 문구들이 들어있는데 말그대로 맛보기였다. 제대...
댓글 없음:
댓글 쓰기