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