源代码
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>享学课堂</title> </head> <body> <p>创建和使用对象方法.</p> <p>对象方法是函数定义,存储为属性值.</p> <p id="demo"></p> <script> var person = { firstName: "John", lastName : "Doe", id : 5566, fullName : function() { return this.firstName + " " + this.lastName; } }; document.getElementById("demo").innerHTML = person.fullName(); </script> </body> </html>
运行结果