问题描述
出于好奇,window.prompt和JavaScript中的提示之间有任何区别。
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");
我用过
var yourName = prompt("Please enter your first name here\n");
这是一个书面考试,所以我觉得它没有多大区别。
It is a written exam so i felt it wouldn't make much difference.
推荐答案
通常是, window.prompt ===提示
。但它确实取决于你的范围,有人可能已声明 window
或提示
变量的值与全局值不同范围。
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?.
这篇关于window.prompt和prompt之间有什么真正的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!