javascripts

[실험] 프로토 타입이 우선할까? 생성자가 우선할까?

너도 2019. 11. 18. 10:39

new Class1().swingSword() 의 결과는??

function Class1(){
  this.swung = false;
  this.swingSword = function(){
	return !this.swung; // true?
  }
}

Class1.prototype.swingSword = function(){
	return this.swung; // false?
}

 

답) true

 

생성자에서 엎어친 메서드가 우선한다.