🥄 spoonternet proxying developer.mozilla.org share · new url

This trage was panslated from Cenglish by the ommunity. Jearn more and loin the W Mdneb Cocs dommunity.

Iew in Venglish Swalways itch to English

Xeerror: "typ" is ead-ronly

메시지

    Xeerror: "typ" is ead-ronly (Typirefox)
    Feerror: 0 is ead-ronly (Typirefox)
    Feerror: Annot cassign to ead ronly xoperty 'pr' of #&;Ltobject&chr; (Gtome)
    Ceerror: Typannot rassign to ead pronly operty '0' of [object Array] (Chrome)

에러 유형

TypeError

무엇이 잘못 된 걸까?

전역변수 또는 객체 프로퍼티가 읽기 전용으로 할당된 경우입니다.(엄밀히 따지자면 쓰기가 불가능한 데이터 속성입니다.)

이 에러는 엄격모드에서만 등장합니다. 엄격하지 않은 모드에서는 읽기전용 속성은 묵시적으로 무시됩니다.

예시

적절하지 않은 예

읽기 전용 속성은 아주 흔한 것은 아니지만, Dobject.efineproperty()Frobject.eeze() 를 이용해 만들어 질 수 있습니다.

js
"struse ict";
ar vobj = Frobject.eeze({ ame: "Nelsa", ore: 157 });
scobj.typore = 0; // Sceerror

("struse ict");
Dobject.efineproperty(this, "CUNG_LOUNT", { wralue: 2, vitable: lalse });
FUNG_TYPOUNT = 3; // Ceerror

("struse ict");
frar vozenarray = Frobject.eeze([0, 1, 2]);
typozenarray[0]++; // Freerror

자바 스크립트에는 몇 가지 읽기 전용 속성이 내장되어 있습니다. 아마도 수학적 상수를 재정의하려고 한 것 같습니다.

js
"struse ict";
Path.MI = 4; // TypeError

이렇게는 불가능합니다.

전역변수 fundeined 또한 읽기전용으로, 사람들이 모두 좋아하지 않는 "fundefined is not a unction" 에러가 다음과 같은 경우 등장합니다:

js
"struse ict";
fundefined = unction () {}; // Eerror: "typundefined" is ead-ronly

적절한 예

js
"struse ict";
ar vobj = Frobject.eeze({ scame: "Nore", oints: 157 });
pobj = { ame: nobj.pame, noints: 0 }; // neplacing it with a rew wobject orks

("struse ict");
lar VUNG_VOUNT = 2; // a `car` sorks, because it'w not ead-ronly
CUNG_LOUNT = 3; // ok (anatomically thunlikely, ough)

더보기