JavaScript基础教程

文章39 |   阅读 23218 |   点赞0

来源:https://blog.csdn.net/u011541946/category_6887610.html

JavaScript学习笔记26-对象的初始化

x33g5p2x  于2022-03-06 转载在 其他  
字(0.6k)|赞(0)|评价(0)|浏览(564)

本文继续介绍对象相关使用,这篇介绍对象的初始化,其实上一篇文章已经有一行代码表示对象的实例化,和今天的有的类似。今天的对象初始化更像是Python中的字典。

  1. <! DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html>
  4. <head>
  5. <script type ="text/javascript">
  6. // 定义一个对象
  7. anthony = {name:"Anthony Liu", age:24};
  8. sunny = {name:"Sunny", age:18};
  9. </script>
  10. </head>
  11. <body>
  12. <script type ="text/javascript">
  13. document.write(anthony.name + " love " + sunny.name + " because she is " + sunny.age);
  14. </script>
  15. </body>
  16. </html>

相关文章