标签:
JavaScript中的所有事物都是对象:字符串,数值,数组,函数
var message = "Hello World";
var x = message.length;
console.log(x);
var message = "Hello World";
var y = message.toUpperCase();
console.log(y)
1 person = new Object(); 2 person.firstname = "Bill"; 3 person.lastname = "Gates"; 4 person.age = 56; 5 person.eyecolor = "blue"; 6 document.write(person.firstname + " is " + person.age + " years old");
person={firstname:"John",lastname:"Doe",age:50,eyecolor:"blue"};
1 function person(firstname,lastname,age,eyecolor) 2 { 3 this.firstname=firstname; 4 this.lastname=lastname; 5 this.age=age; 6 this.eyecolor=eyecolor; 7 } 8 myFather = new person("Bill","Gates",56,"blue"); 9 document.write(myFather.firstname + " is " + myFather.age + " years old.");
1 person.firstname="Bill"; 2 person.lastname="Gates"; 3 person.age=56; 4 person.eyecolor="blue"; 5 6 x=person.firstname;
Bill把方法添加到JavaScript对象
1 function person(firstname,lastname,age,eyecolor) 2 { 3 this.firstname=firstname; 4 this.lastname=lastname; 5 this.age=age; 6 this.eyecolor=eyecolor; 7 8 this.changeName=changeName; 9 function changeName(name){ 10 this.lastname = name; 11 } 12 } 13 myMother = new person("momo","lili",67,"black"); 14 myMother.changeName("LILI"); 15 document.write(myMother.lastname);
1 var person={fname:"Bill",lname:"Gates",age:56}; 2 for (x in person) 3 { 4 txt=txt + person[x]; 5 } 6 document.getElementById("demo").innerHTML=txt;
标签:
原文地址:http://www.cnblogs.com/liubeimeng/p/5504378.html