What is the difference between open() and window.open() in Firefox?

前端 未结 6 2114
抹茶落季
抹茶落季 2021-01-18 10:16

In answering my question Pumbaa80 found a difference between calling open() and window.open(), try the following examples in Firefox

6条回答
  •  耶瑟儿~
    2021-01-18 11:03

    Your two fiddles work the same for me on Chrome.

    However, the two lines of code

    window.open(...);

    and

    open(...);

    are NOT equivalent. The only time they will be equivalent is if your current executing scope does not provide a new definition for open, causing the interpreter to look in the higher scopes until it reaches the global scope and finds window.open.

    You can see this in action in this fiddle:

    var test = function () {
        var open = function () {
          alert('uh oh');  
        };
    
        window.open('www.google.com');
        open('www.google.com');
    };
    
    test();
    

提交回复
热议问题