我已经创建了一个对象,但是在调用时,它说未定义(JavaScript)

时间:2019-01-24 07:04:22

标签: javascript

我看了一个教程,做了同样的事情。现在,此“未定义”错误不断显示我什至在其他浏览器中尝试过但结果相同。我是JS新手,需要帮助,谢谢。

<html>
<head>
<script type="text/javascript">


function person(name, age){
		this.name = name;
		this.age = age;

}

		
		var milz = new person("milz", 23);
		var stefi = new person("stefi", 19);

</script>
</head>




<body>
<script type="text/javascript">
document.write("hello ");
document.write(stefi.age);


</script>
</body>
</html>

1 个答案:

答案 0 :(得分:2)

<html>
<head>
<script type="text/javascript">


function person(name, age){
		this.name = name;
		this.age = age;
		
		
}
var milz = new person("milz", 23);
		var stefi = new person("stefi", 19);

</script>
</head>




<body>
<script type="text/javascript">
document.write("hello ");
document.write(stefi.age);


</script>
</body>
</html>