admin管理员组文章数量:1389754
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.
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.
Share Improve this question edited Apr 20, 2014 at 16:09 j08691 208k32 gold badges269 silver badges280 bronze badges asked Apr 20, 2014 at 16:07 user3364498user3364498 4891 gold badge9 silver badges14 bronze badges 2- 2 Nope, they're the same. – j08691 Commented Apr 20, 2014 at 16:08
-
2
when you declare a variable that is in the root scope, you can find it inside
window.
as well.var test = 10;
window.test
will be 10. therefore they are exactly the same function (not a copy) – user652649 Commented Apr 20, 2014 at 16:09
2 Answers
Reset to default 6Usually 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?.
var person = prompt("Please enter your name", "Harry Potter");
if (person != null) {
document.getElementById("demo").innerHTML =
"Hello " + person + "! How are you today?"; }
usually window.prompt === prompt because,
A prompt dialog contains a single-line textbox, a Cancel button, and an OK button, and returns the (possibly empty) text the user entered into that textbox. ... alert Dialog boxes are modal windows; they prevent the user from accessing the rest of the program's interface until the dialog box is closed
本文标签: javascriptAny real difference between windowprompt and promptStack Overflow
版权声明:本文标题:javascript - Any real difference between window.prompt and prompt? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744707374a2620921.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论