Why is document.all falsy?

前端 未结 4 1438
难免孤独
难免孤独 2020-11-29 21:52

document.all is a non-primitive object in the DOM that is falsy.

For example, this code doesn\'t do anything:

if (document.all) {
    al         


        
4条回答
  •  广开言路
    2020-11-29 21:58

    In short, it's to make BOTH of these code samples work. Browsers have to do this so that old web pages will continue to work.

    Sample 1

    // Internet Explorer
    if (document.all) {
        useActiveX()
    }
    // Netscape Navigator
    else {
        useOldButStillWorkingCode()
    }
    

    Sample 2

    document.all.output.innerHTML = 'Hello, world!'
    

提交回复
热议问题