-4
我已经定义了一个包含2个属性和名为fullname的函数的对象。当我调用函数全名时,我看到显示了一个额外的显示行。Javascript对象中的调用函数
<html>
<head>
<script>
function person(firstname,lastname){
this.firstname = firstname;
this.lastname = lastname;
var id = 1;
this.fullname = function(){
console.log("firstname = " + firstname + " lastname = " + lastname);
}
}
x = new person("Bob","McDonald");
console.log(x.firstname);
console.log(x.fullname());
console.log("Display finish");
</script>
</head>
<body>
This is the body
</body>
</html>
输出从firebug-
鲍勃
basics.html(第14行)姓名=鲍勃姓氏=麦当劳
basics.html(第9行)未定义
basics.html(线15)显示屏完成
你的问题是? –
什么是您的输出?它应该是什么? “看到显示的另外一行显示”是什么意思? – h2ooooooo
函数'fullname'返回'undefined'。 'console.log(x.fullname())'返回值的日志。 – apsillers