This is an artifact of the way the Javascript console works when you log an object. The log doesn't contain a copy of all the object properties, it just contains a reference to the object. When you click on the disclosure triangle, it then looks up all the properties and displays them.
這是JavaScript console 在log一個對象的機制形成的。log 沒有包含對象的全部屬性,它只包含了對這個對象的引用。當你點擊展開時,他纔會給你找那個對象的屬性。javascript
In this case, at the time you call console.log(e)
, there's a DOM element in the currentTarget property. But sometime later, that property is reset to null
for some reason. When you expand the event object, that's what you see.
你的狀況是,當調用console.log(e)
時,currentTarget屬性是有值的,可是事後這個值就被重置爲null
了。因此當你展開事件對象,看到的就是null
。java
A simple example that demonstrates this is:
這裏有一個例子:this
var foo = { }; for (var i = 0; i < 100; i++) { foo['longprefix' + i] = i; } console.log(foo); foo.longprefix90 = 'abc';
When you view the object in the console, you'll see that foo.longprefix90 contains "abc", even though it contained 90 at the time that console.log(foo) was called.
雖然在調用console.log(foo)
的時候foo.longprefix90
應該是90
,可是當你在console裏瀏覽object的時候你會看到foo.longprefix90
是abc
。code
The demonstration needs to use an object with lots of properties. When it's logging, it shows the first few properties that fit in the console, so those are in the early snapshot. Only properties after that display this anomalous behavior.
這個狀況須要一個屬性超多的對象,當它被log的時候,它展現頭幾個屬性是當時的快照,後面的屬性纔會出現這個異常。對象