When I run the following code:
var obj = {get foo(){return false}};
Object.create(obj);
in the Chrome DevTools console, I get the following:
{
foo: (...)
}
where I have to specifically click to invoke the getter, rather than the invocation happening automatically.
However when I run the following code:
var obj = new CustomEvent('test_event', {detail: false});
obj
I see the following result:
CustomEvent{
bubbles: false
cancelBubble: false
cancelable: false
composed: false
currentTarget: null
defaultPrevented: false
detail: false
eventPhase: 0
isTrusted: false
path: []
returnValue: true
srcElement: null
target: null
timeStamp: 3209573.314999696
type: "test_event"
}
On closer inspection, it is discovered that detail
is a getter on the CustomEvent
prototype, but it is invoked immediately i.e. no (...)
.
In this issue on the Firefox DevTools Github page [that I stumbled when doing research on how Chrome handles getter invocation], a respondent says:
Chrome does not invoke unsafe getters by default, but you can click (...) to do so
What is meant by a getter being unsafe? Why is this [CustomEvent
] getter invoked, and the earlier example not? Why is it considered safe
?