HTML:
<button onclick="foo(event);">Test</button>
Javascript:
window.foo = function(event) {
console.log(JSON.stringify(event));
}
Console Result:
{"isTrusted":true}
It is happening on Chrome. I haven't tested other browsers yet.
HTML:
<button onclick="foo(event);">Test</button>
Javascript:
window.foo = function(event) {
console.log(JSON.stringify(event));
}
Console Result:
{"isTrusted":true}
It is happening on Chrome. I haven't tested other browsers yet.
There are a number of reasons why some properties do not get included in JSON.stringify:
function
s, which cannot be stringifiedIf you need to include extra data, your best bet is to manually construct a fresh object with the things you want to include:
window.foo = function(event) {
console.log(JSON.stringify({keyCode: event.keyCode));
}
The event itself is full of prototype functions - which are getting hidden by stringify (as ForbesLindesay already pointed out).
Otherwise it's not common to see onclick in HTML markup (since it generates very tight dependencies with your code).
Most browsers (beyond IE7) also allow you unpacking of values inside the console - which you can see here: http://jsfiddle.net/djf2nxwd/14/
document.getElementById('foo').onclick = (event) => {
console.log(JSON.stringify(event));
console.log(event);
};
That's probably the behaviour you expected.