JavaScript数据类型

JavaScript数据类型

1.JavaScript中所有的事物都是对象,比如String,Date,Array等;JavaScript允许自定义对象。

2.JavaScript 是面向对象的语言,但 JavaScript 不使用类。在 JavaScript 中,不会创建类,也不会通过类来创建对象。

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
 5     </head>
 6     <body>
 7         <script>
 8             //构造器
 9             function person(firstname, lastname, age, eyecolor) {
10                 // 对象赋值
11                 this.firstname = firstname;
12                 this.lastname = lastname;
13                 this.age = age;
14                 this.eyecolor = eyecolor;
15                 //在构造器内部定义对象的方法
16                 //类似方法声明
17                 this.changeName = changeName;
18                 //方法定义
19                 function changeName(name) {
20                     this.lastname = name;
21                 }
22             }
23             
24             myMother = new person("Steve", "Jobs", 56, "green");
25             myMother.changeName("Ballmer");
26             document.write(myMother.lastname);
27         </script>
28     </body>
29 </html>
View Code

3.JavaScript中的for...in遍历所有属性

1 var person={fname:"Bill",lname:"Gates",age:56};
2 var txt = "";
3 for (x in person) {
4   txt = txt + person[x];
5 }
View Code

 

posted @ 2013-12-06 10:30  slowalker  阅读(157)  评论(0编辑  收藏  举报