: http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f9f.html 인용구 :개체에 대한 유형이 지정되지 않은 변수의 이점은 무엇입니까? null과 undefined의 차이점은 무엇입니까? 이에 따라
유형이 지정되지 않은 입력 변수가 객체의 변수와 동일하지 않다. 주요 차이점은 형식이 지정되지 않은 변수는 특수 값을 정의되지 않은 상태로 유지할 수 있지만 Object 유형의 변수는 해당 값을 보유 할 수 없다는 것입니다.
그러나 내가로 테스트 할 때 :
var objTest:Object = 123;
var untypedTest:* = 123;
objTest = undefined;
untypedTest = undefined;
//This is understandable but why was the assignment even allowed?
trace(objTest); // prints null
trace(untypedTest); // prints undefined
objTest=null;
untypedTest = null;
//This is also understandable ... both can store null
trace(objTest); // prints null
trace(untypedTest); // prints null
//If they are null whey are they being equal to undefined?
if(objTest==undefined)
trace("obj is undefined");
if(untypedTest==undefined)
trace("untyped is undefined");
//Because null is same as undefined!
if(null==undefined)
trace("null is same as undefined?");
두 질문 :
- 왜 할당이 OBJ 허용 undefined로한다?
- null을 undefined와 비교하면 true가 반환됩니다 (Object에 null이 저장된 경우에도 마찬가지 임). 동등한 경우 null과 undefined의 차이점은 무엇입니까?
굉장한 ... 완벽한 설명 – basarat
또한 키가 객체에 있는지 확인하기 위해 undefined를 사용합니다. 즉, if (myObj [ "someKey"] == undefined) // 추가하십시오. 체크에 null을 사용할 수도 있지만 누군가 null을 값으로 저장하려고 할 때 중단됩니다. 'myObj [ "someKey"] = null; // 유효 ' – divillysausages
@divillysausages,'undefined'를 사용하는 것이 더 이상 사용되지 않습니다. 혼동을 막기 위해서 (때문에), null가 아니면 안됩니다. '값 없음'으로 키를 저장해야하는 경우 '0'또는 '거짓'만 사용하십시오 (값이없는 키의 위치는 무엇이겠습니까?). –