객체 Method,this

김범준·2021년 7월 14일
0

Javascript

목록 보기
13/22

객체안의 Method

const Person = {
	name : 'Kim',
  	age : 33,
  	walk : function() {
    	console.log("걷고 있습니다.");
    }
	//walk(){
	//	console.log("걷고 있습니다.");
	//} 이렇게 함수를 쓸 수 있다.
}

This

객체 자기자신을 지칭, Arrow function을 사용하면 this는 브라우저에서는 window, Node js에서는 global을 지칭한다.

const Person = {
	name : 'Kim',
  	age : 33,
  	walk : function() {
    	console.log(`${this.name},걷고 있습니다.`);
    }
}

여기서의 this.name은 Person이란 객체의 name프로퍼티이다.

0개의 댓글

Powered by GraphCDN, the GraphQL CDN