이 번역은 완료되지 않았습니다. 이 문서를 번역해 주세요.
ReferenceError 객체는 존재하지 않는 변수를 참조했을 때 발생하는 에러를 나타냅니다.
문법
new ReferenceError([message[, fileName[, lineNumber]]])
파라미터
message- 선택사항. 에러에 대한 설명문
fileName- 선택사항. 예외가 발생한 코드를 포함하는 파일의 이름
lineNumber- 선택사항. 예외가 발생한 코드의 줄 번호
설명
ReferenceError는 선언된 적이 없는 변수를 참조하려고 할 때 발생합니다.
프로퍼티
ReferenceError.prototype- ReferenceError 객체에 프로퍼티를 추가할 수 있습니다.
메서드
전역 ReferenceError는 메서드를 가지고 있지 않습니다. 그러나 상속 관계에서 프로토타입 체인을 통해 일부 메서드를 가질 수 있습니다.
ReferenceError 인스턴스
프로퍼티
ReferenceError.prototype.constructor- Specifies the function that created an instance's prototype.
ReferenceError.prototype.message- Error message. Although ECMA-262 specifies that
ReferenceErrorshould provide its ownmessageproperty, in SpiderMonkey, it inheritsError.prototype.message. ReferenceError.prototype.name- Error name. Inherited from
Error. ReferenceError.prototype.fileName- Path to file that raised this error. Inherited from
Error. ReferenceError.prototype.lineNumber- Line number in file that raised this error. Inherited from
Error. ReferenceError.prototype.columnNumber- Column number in line that raised this error. Inherited from
Error. ReferenceError.prototype.stack- Stack trace. Inherited from
Error.
메서드
Although the ReferenceError prototype object does not contain any methods of its own, ReferenceError instances do inherit some methods through the prototype chain.
예제
ReferenceError 처리하기
try {
var a = undefinedVariable;
} catch (e) {
console.log(e instanceof ReferenceError); // true
console.log(e.message); // "undefinedVariable is not defined"
console.log(e.name); // "ReferenceError"
console.log(e.fileName); // "Scratchpad/1"
console.log(e.lineNumber); // 2
console.log(e.columnNumber); // 6
console.log(e.stack); // "@Scratchpad/2:2:7\n"
}
ReferenceError 생성하기
try {
throw new ReferenceError('Hello', 'someFile.js', 10);
} catch (e) {
console.log(e instanceof ReferenceError); // true
console.log(e.message); // "Hello"
console.log(e.name); // "ReferenceError"
console.log(e.fileName); // "someFile.js"
console.log(e.lineNumber); // 10
console.log(e.columnNumber); // 0
console.log(e.stack); // "@Scratchpad/2:2:9\n"
}
명세
| Specification | Status | Comment |
|---|---|---|
| ECMAScript 3rd Edition (ECMA-262) | Standard | Initial definition. |
| ECMAScript 5.1 (ECMA-262) The definition of 'ReferenceError' in that specification. |
Standard | |
| ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'ReferenceError' in that specification. |
Standard | |
| ECMAScript Latest Draft (ECMA-262) The definition of 'ReferenceError' in that specification. |
Draft |
브라우저 호환성
이 페이지의 호환성 테이블은 구조화된 데이터로부터 생성됩니다. 해당 데이터를 개선하고 싶다면 https://github.com/mdn/browser-compat-data을 체크아웃하고 저희에게 풀 리퀘스트를 보내주십시오.
Update compatibility data on GitHub
| Desktop | Mobile | Server | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ReferenceError | Chrome Full support Yes | Edge Full support Yes | Firefox Full support 1 | IE Full support Yes | Opera Full support Yes | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Edge Mobile Full support Yes | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support Yes | nodejs Full support Yes |
Legend
- Full support
- Full support