向已有对象添加新属性
- <!DOCTYPE html>
- <html>
- <body>
- <h1>JavaScript 对象属性</h1>
- <p>您可以向现有对象添加新属性。</p>
- <p id="demo"></p>
- <script>
- var person = {
- firstname:"Bill",
- lastname:"Gates",
- age:62,
- eyecolor:"blue"
- };
- person.nationality = "English";
- document.getElementById("demo").innerHTML =
- person.firstname + " is " + person.nationality + ".";
- </script>
- </body>
- </html>