Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
객체 혹은 변수를 생성자로 사용하려고 했습니다, 하지만 객체(혹은 변수)가 생성자가 아닙니다. 생성자가 무엇인지에 대한 자세한 정보는 constructor 혹은 new operator 를 참조하시기 바랍니다.
String 혹은 Array와 같이 new,를 사용하여 생성할 수 있는 전역 객체들이 있습니다. 하지만 일부 전역 객체들은 그렇지 않고 속성과 메서드가 정적입니다. 다음의 JavaScript 표준 내장 객체들은 생성자가 아닙니다: Math, JSON, Symbol, Reflect, Intl, SIMD, Atomics.
Generator functions 또한 생성자로 사용될 수 없습니다.
자동차(car) 객체를 만들고자 한다고 가정합니다. 이 객체의 타입을 car라 하고 make, model, and year 세 개의 프로퍼티를 갖습니다. 이를 위해 다음과 같은 함수를 작성할 것입니다:
이제 다음과 같이 mycar 라 불리는 객체를 생성할 수 있습니다:
즉시 실행되는 프라미스를 반환하는 경우에는 *새로운 Promise(...)*를 생성할 필요가 없습니다.
아래는 올바른 방법이 아닙니다(프라미스 생성자가 제대로 호출되고 있지 않습니다). TypeError: this is not a constructor 예외를 던지게 됩니다:
대신, Promise.resolve() 혹은 Promise.reject() 정적 메서드를 사용하십시오:
This page was last modified on 2023년 10월 25일 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.