gpt4 book ai didi

javascript - 调用 alert() 和 sqrt() 的方式有何不同?

转载 作者:行者123 更新时间:2023-12-03 21:07:03 24 4
gpt4 key购买 nike

window.alert("Hello!");

相同
alert("Hello!");

// Works
Math.sqrt(4);
Math.floor(3.55);
Math.round(2.5);

// Does not work
sqrt(4);
floor(3.55);
round(2.5);

为什么会这样?我什么时候需要键入对象(例如 Mathwindow),什么时候不需要?

最佳答案

在浏览器中,window 的属性,如 alertdocument,是全局的。

alertwindow.alertMath.sqrtwindow.Math.sqrt .

When do I need to type the object (such as Math or window) and when not?

本质上,如果对象是window,则您不需要拥有它。对于所有其他情况,您可以这样做。

关于javascript - 调用 alert() 和 sqrt() 的方式有何不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22779627/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com