?????? ??
JavaScript ??
JavaScript? ?? ?? ???, ?, ??, ?? ? ?????.
?? JavaScript? ??? ?? ??? ?????.
?? ?? ?????
JavaScript? ???, ??, ?? ?? ?? ?? ?? ??? ?????. ??? ??? ???? ?? ??? ??? ?????.
?? ??? ??? ? ? ????. ?? ??? ??? ? ????. ???? ??? ? ? ????. ??? ?? ???? ?????.
JavaScript ??
??? ?? ??? ??? ???? ????. ???? ??? ???? ????.
??? ??? ?????
??? ??? ??? ????.
?? ??? ????? ?? ??? ??? ????.
objectName.propertyName
? ???? String ??? ?? ??? ???? ???? ??? ?????.
var message="Hello World!";
var x= message.length ;
? ??? ??? ? x? ?? ??? ????.
12
??? ????? ??
???? ??? ?? ??? ? ?? ?????.
?? ??? ???? ???? ??? ? ????.
objectName.methodName()
? ???? String ??? toUpperCase() ???? ???? ???? ???? ?????.
var message="Hello world!" ;
var x=message.toUpperCase();
? ??? ??? ? x ?? ??? ????.
HELLO WORLD!
JavaScript ?? ???
JavaScript? ???? ???? ??? ???? ?? ? ????. .
? ??? ???? ???? ? ??? ????.
??? ???? ?? ? ?? ??? ???? ??? ??? ?? ??? ? ????? ?????.
?? ???? ??
? ???? ??? ?????. ??? ? ????? ??? ??? ? ?? ??? ??????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <script> var person=new Object(); person.firstname="jack"; person.lastname="Doe"; person.age=35; person.eyecolor="blue"; document.write(person.firstname + " is " + person.age + " years old."); </script> </body> </html>
?? ??(?? ??? ??):
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <script> person={firstname:"John",lastname:"Doe",age:50,eyecolor:"blue"} document.write(person.firstname + " is " + person.age + " years old."); </script> </body> </html>
?? ??? ??
? ???? ??? ???? ??? ?????.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> </head> <body> <script> function person(firstname,lastname,age,eyecolor){ this.firstname=firstname; this.lastname=lastname; this.age=age; this.eyecolor=eyecolor; } myFather=new person("jack","Doe",35,"blue"); document.write(myFather.firstname + " is " + myFather.age + " years old."); </script> </body> </html>
JavaScript?? ?? ????? ?? ?? ?? ??? ????? ??? ?? ??(???)? ?????.
JavaScript ?? ???? ??
?? ???? ??? ??? ?? ? ?? ????? ??? ? ????.
var myFather=new person("John","Doe",50," blue") ;
var myMother=new person("Sally","Rally",48,"green");
JavaScript ??? ?? ??
??? ?? ???? ?? ??? ? ??? ??? ? ????.
personObj? ?? ????? ???? ??? ??? ?? ??? ??? ??? ? ????: ??, ?, ?? ? ? ??:
person.firstname="John";
person.lastname="Doe"; person.eyecolor="blue";
x=person.firstname;
T? ??? ??? ?, ??? ?? Functions? ?.
??? ?? ?? ??? ??? ???:
function person(firstname,lastname,age,eyecolor){ this.firstname=firstname; this.lastname=lastname; this.age=age; this.eyecolor=eyecolor; this.changeName=changeName; function changeName(name){ this.lastname=name; } }
changeName() ?? ??? ?? ??? ? ??? ?????.
JavaScript ???
JavaScript? ?? ?? ????? JavaScript? ???? ???? ????.
JavaScript??? ???? ???? ??? ?? ?? ?? ??? ????? ????? ??? ???? ????. JavaScript? ??? ??? ?? ????? ?????. JavaScript for...in ??
JavaScript for...in ?? ??? ??? ?????.
Syntax
for (variable in object) { 執(zhí)行的代碼…… }
??: for...in ??? ?? ??? ? ??? ?? ? ?? ?????.