开发者

Explanation on this Javascript check

function doSomething(e) {
    var targ;
    if (!e) var e = window.event; //<<<< what does it do this check?
    if (e.target) targ = e.target;
}

Wh开发者_JS百科y do we need to check this?


This adds compatibility with older (Internet Explorer?) browsers that didn't support passing the event object to handlers but instead defined them on the window object.

Also the var is not needed in var e = window.event because it's already declared (parameter).

It can also be written as e = e || window.event;


Basically this if checks if e variable is set. If it isn't - it is assigned a value of window.event (the window event that happened)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜