JavaScript基礎----26JS內建物件-什麼是物件
阿新 • • 發佈:2019-01-25
<!DOCTYPE html> <!--JS內建物件-什麼是物件--> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body> <!--建立物件的第1種方法,定義並建立物件例項--> <script> people = new Object(); people.name ="劉備"; people.age="63"; document.write("name"+people.name+">>>>>>>>>>>"+"age"+people.age+"<br/>"); </script> <!--建立物件的第1種方法,定義並建立物件例項--> <script> people={name:"zhang3",age:"63"}; document.write(people.name+">>>>>>>"+people.age+"<br/>"); </script> <!--建立物件的第2中方法,使用函式定義物件,然後建立新的物件例項--><!--有點像java語言中的構造方法--> <script> function dongwu(name,age){ this.name = name; this.age = age; } mydongwu= new dongwu("li4",30); document.write(mydongwu.name+">>>>>"+mydongwu.age); </script> </body> </html>