2
JS를 배우려고하는데 객체 속성에 대해 혼란 스럽습니다. 아래 예에서 정의되지 않은 함수를 사용하여 오류를 생성했으며 오류 객체의 속성과 메소드를 얻으려고합니다. e.message는 오류 메시지를 인쇄 할 수 있지만 오류 개체 속성으로 메시지를 가져올 수 없습니다. 여기서 무슨 일이 일어나고있는거야?자바 스크립트 오류 객체 속성
try{
unknownFunction();// undefined function here
}catch(e){
console.log(e); // it is ReferenceError
console.log(e.message);//message
console.log(typeof e); // object
console.log(e instanceof ReferenceError); // true
console.log(e === ReferenceError); // false
for(var propertyName in e) {
console.log("Name "+propertyName+" and Value "+e[propertyName]);
} // []
let allKeys = Object.keys(e);
console.log(allKeys);// []
let fnKeys = allKeys.filter(key => typeof myObj[key] == 'function');
console.log(fnKeys); // []
}
repl.it https://repl.it/FKHn/6 –
당신이'message'이 발생할 것으로 예상한다는 것을 의미합니까 'allKeys' 배열? – Xufox
@Xufox 예 당신이 그것을 못 박았습니다, 고마워요! –