JavaScript constructor 属性

constructor 属性返回所有 JavaScript 变量的构造函数。

<!DOCTYPE html>

<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>

<p> constructor 属性返回变量或对象的构造函数。</p>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML =
"john".constructor + "<br>" +
(3.14).constructor + "<br>" +
false.constructor + "<br>" +
[1,2,3,4].constructor + "<br>" +
{name:'john', age:34}.constructor + "<br>" +
new Date().constructor + "<br>" +
function () {}.constructor;
</script>

</body>
</html>

posted @ 2020-11-21 00:00  xjspyx  阅读(63)  评论(0)    收藏  举报