Any real difference between window.prompt and prompt?

不问归期 提交于 2019-12-02 09:15:29

问题


Just out of curiosity is there any difference between window.prompt and prompt in JavaScript.

For one of the answers to my exam questions the teacher uses

var yourName = window.prompt("Please enter your first name here\n");

and I used

var yourName = prompt("Please enter your first name here\n");

It is a written exam so i felt it wouldn't make much difference.


回答1:


Usually yes, window.prompt === prompt. Yet it does depend on your scope, someone might have declared window or prompt variables with different values than those in the global scope.

For further details have a look at Is window really global in Javascript?. You (and your teacher) also might be interested in Why is it beneficial to rely on the scope chain alone and avoid explicitly referencing the head object in Javascript?.



来源:https://stackoverflow.com/questions/23184598/any-real-difference-between-window-prompt-and-prompt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!