W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <h1>JavaScript <b>this</b> 关键词</h1> <p>在本例中,<strong>this</strong> 引用 person2,即使它是 person1 的方法:</p> <p id="demo"></p> <script> var person1 = { fullName: function() { return this.firstName + " " + this.lastName; } } var person2 = { firstName:"Bill", lastName: "Gates", } var x = person1.fullName.call(person2); document.getElementById("demo").innerHTML = x; </script> </body> </html>