JavaScript中可以直接通过类似python字典的方式定义对象,下面的代码你一看就能明白怎么回事,不用多说。
<!DOCTYPE html> <html> <body> <script> person={firstname:"John",lastname:"Doe",age:50,eyecolor:"blue"} document.write(person.firstname + " is " + person.age + " years old."); </script> </body> </html>