클래스 불러올때 new 클래스네임() 클래스네임() 두개가 무슨차이인가요?

class something{
}
여기서
new something()
이거와
songthing()
무슨차이인가욤. ?

class로 선언 되어 있는 something은 new 연산자 없이 사용할 수 없습니다.
다음과 같은 에러가 나게 됩니다.

Uncaught TypeError: Class constructor something cannot be invoked without 'new'

class가 아닌 function의 경우, 함수를 그대로 호출한 경우와 new 연산자를 통한 호출의 차이는 아래 코드와 링크를 참고하세요.

function something(){
  this.type="wow"
}
const x = new something();
console.log(window.type); //undefined
console.log(x.type); //wow

const y = something();
console.log(window.type); //wow
console.log(y); //undefined
1개의 좋아요

자세한 설명 감사합니다.

1개의 좋아요