运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>The JavaScript <i>this</i> Keyword</h1> <p>In this example <strong>this</strong> refers to person2, even if it is a method of person1:</p> <p id="demo"></p> <script> const person1 = { fullName: function() { return this.firstName + " " + this.lastName; } } const person2 = { firstName:"John", lastName: "Doe", } let x = person1.fullName.call(person2); document.getElementById("demo").innerHTML = x; </script> </body> </html>