
Но JSON.stringify(event) возвращает только строку '{"isTrusted":true, в которой отсутствуют все важные свойства Я ищу.
Я искал и пробовал несколько решений, но ни одно из них не дало ожидаемого результата:
1.
Код: Выделить всё
> JSON.stringify(event, Object.getOwnPropertyNames(event))
< '{"isTrusted":true}'
Код: Выделить всё
> JSON.stringify(event, (function(seen, k, value) {
console.log(`k=${k} value=${value}`);
if (typeof value === 'object' && value !== null) {
if (seen.indexOf(value) !== -1) return;
else seen.push(value);
}
return value;
}).bind(null, []));
< '{"isTrusted":true}'
Код: Выделить всё
> for(k in event){
console.log(k);
}
< undefined
Код: Выделить всё
> event.toString()
< '[object ErrorEvent]'
Код: Выделить всё
> Object.keys(event)
< ['isTrusted']
Код: Выделить всё
JSON.stringify(event, ["isTrusted",
"bubbles",
"cancelBubble",
"cancelable",
"colno",
"composed",
"currentTarget",
"defaultPrevented",
"error",
"eventPhase",
"filename",
"lineno",
"message",
"returnValue",
"srcElement",
"target",
"timeStamp",
"type"])
'{"isTrusted":true,"bubbles":false,"cancelBubble":false,"cancelable":true,"colno":5,"composed":false,"currentTarget":{},"defaultPrevented":false,"error":"{\\"reason\\":\\"GET /problem/8a9463a241657d960a68ca73f2a532f3 failed: 500\\"}","eventPhase":2,"filename":"http://localhost:3000/js/chess.js","lineno":26,"message":"Uncaught {\\"reason\\":\\"GET /problem/8a9463a241657d960a68ca73f2a532f3 failed: 500\\"}","returnValue":true,"srcElement":{},"target":{},"timeStamp":168.59999999403954,"type":"error"}'
Как мне перечислить тот же набор свойств объекта, который я вижу в консоли?>
Подробнее здесь: https://stackoverflow.com/questions/798 ... he-console
Мобильная версия