<!doctype html>
<html>
<head>
<script type="text/javascript">
/*
reinaldo_init = {name: "reinaldo", age:22};
Agregar metodos a los objetos
*/
function people(name, age){
this.name = name;
this.age = age;
this.retirement = yearsLeft; //NO LLEVA PARENTESIS AL RELACIONAR LA FUNCION
}
function yearsLeft(){
var numYears = 65 - this.age;
return numYears;
}
var reinaldo = new people("reinaldo acosta", 22);
</script>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<script type="text/javascript">
//Calling code
document.write(reinaldo.retirement());
</script>
</body>
</html>
好吧,在身体标签之后,我尝试打印reinaldo的退休,问题是,我输入reinaldo.retirement()并且它没有提供任何东西......但是如果我将其更改为bucky,它实际上会回归退休年...有人可以告诉我为什么JavaScript不接受我的名字,或者为什么当我使用我的名字(reinaldo)时它不起作用?
<!doctype html>
<html>
<head>
<script type="text/javascript">
/*
reinaldo_init = {name: "reinaldo", age:22};
Agregar metodos a los objetos
*/
function people(name, age){
this.name = name;
this.age = age;
this.retirement = yearsLeft; //NO LLEVA PARENTESIS AL RELACIONAR LA FUNCION
}
function yearsLeft(){
var numYears = 65 - this.age;
return numYears;
}
var reinaldo = new people("reinaldo acosta", 22);
</script>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<script type="text/javascript">
//Calling code
document.write(reinaldo.retirement());
</script>
</body>
</html>
&#13;