var people = {
doctor: "M.D",
specialization: "Neurologist",
city: "NY",
patient: "A.H",
print: function() {
document.write("People Object" + "<br>");
document.write(this.doctor + "<br>");
document.write(this.specialization + "<br>");
document.write(this.city + "<br>");
document.write(this.patient + "<br>");
}
}
document.write(people.print());
每function
返回的东西。如果你没有在你的函数return语句,它将返回undefined
。
当您执行功能people.print()
它返回undefined
,而你试图写它document
,这是你想达到什么不正确的方法。
当你的function
已经写在document
文字,你不需要换包装内function
您document.write
执行。
如果您需要在JavaScript中,read this功能的更多信息。