728x90
2024/04/20
-
함수와 this프론트엔드/Javascript 2024. 4. 20. 08:53
function 으로 생성한 함수에는 항상 this 와 prototype 속성이 존재한다. const Shadow = function(){ console.log(this) } console.log(Shadow()) this 는 윈도우 객체이다. console.log(new Shadow()) this 는 생성자함수이다. var Human = function(type){ this.type = type || 'human' } Human.isHuman = function(human){ return human instanceof Human } Human.prototype.breathe = function(){ alert('h-a-a-a-m') } 자바스크립트에서는 객체 복사로 상속한다. 복사하는 원본객체를 프로토..