W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <h1>JavaScript 函数</h1> <p>此例调用 person 的 fullName 方法,在 person1 上使用它:</p> <p id="demo"></p> <script> var person = { fullName: function() { return this.firstName + " " + this.lastName; } } var person1 = { firstName:"Bill", lastName: "Gates" } var person2 = { firstName:"Steve", lastName: "Jobs" } var x = person.fullName.call(person1); document.getElementById("demo").innerHTML = x; </script> </body> </html>