【发布时间】:2018-05-29 11:57:27
【问题描述】:
我正在学习 JavaScript 对象。 我在下面构建了一些编码。当我删除 this.recall=recall 时,它不起作用。但是当我添加 this.recall=recall 时,整个代码都起作用了。我不知道为什么我需要把 this.recall=recall 来得到结果,因为它在函数被调用时没有任何价值。
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
function recall (){
document.write('the height is:'+ this.height+'<br>');
document.write('the weight is:'+ this.weight+'<br>');
document.write('the age is:'+ this.age+'<br>');
}
function Private(height,weight,age){
this.height=height;
this.weight=weight;
this.age=age;
this.recall=recall;
}
</script>
</head>
<body>
<script type="text/javascript">
var man= new Private('170cm','60kg','26-year-old');
man.recall();
</script>
</body>
【问题讨论】:
标签: javascript function object this