gpt4 book ai didi

javascript - 从 JavaScript 调用 Date()。该方法从何而来?

转载 作者:行者123 更新时间:2023-11-28 04:07:23 25 4
gpt4 key购买 nike

我正在尝试开始学习 JavaScript,而不是总是复制它。我知道这可能非常简单,但是 Date() 从何而来?为什么我可以调用它?

<!DOCTYPE html>
<html>
<head>
<script>
function displayDate() {
document.getElementById("demo").innerHTML = Date();
}
</script>
</head>
<body>

<h1>My First JavaScript</h1>
<p id="demo">This is a paragraph.</p>

<button type="button" onclick="displayDate()">Display Date</button>

</body>
</html>

最佳答案

Date() 是一个内置对象,在全局范围内声明,就像 MathArray

您可以在 ECMA specification4.2 语言概述 部分阅读更多相关信息.引用:

ECMAScript defines a collection of built-in objects that round out the definition of ECMAScript entities. These built-in objects include the global object, the Object object, the Function object, the Array object, the String object, the Boolean object, the Number object, the Math object, the Date object, the RegExp object, the JSON object, and the Error objects Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError and URIError.

关于javascript - 从 JavaScript 调用 Date()。该方法从何而来?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13246969/

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