运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h2>JavaScript Object Methods</h2> <p>Object data can be accessed using a getter.</p> <p id="demo"></p> <script> // Create an object: const person = { firstName: "John", lastName: "Doe", get fullName() { return this.firstName + " " + this.lastName; } }; // Display data from the object using a getter: document.getElementById("demo").innerHTML = person.fullName; </script> </body> </html>