ECMA262关键字:
break,else,new,var,case,finally,return,void,catch,for,switch,while,continue,function,this,with,default,if,throw,delete,in,try,do,instanceof,typeof
ECMA262保留字:
abstract,enum,int,short,boolean,export,interface,static,byte,extends,long,super,char,final,native,synchronized,class,float,package,throws,const,goto,private,transient,debugger,implements,protected,volatile,double,import,public
ECMA262原始类型:
Undefined,Null,Boolean,Number,String
String 字面量:
/n 换行
/t 制表符
/b 空格
/r 回车
/f 换页符
// 反斜杠
/' 单引号
/" 双引号
/Onnn 八进制代码nnn(n是0到7中的一个八进制数字)
/xnn 十六进制代码nn(n是0到F中的一个十六进制数字)
/unnnn 十六进制代码nnnn(n是0到F中的一个十六进制数字),表示的Unicode字符
语句:
if(condition) statement1 else statement2
迭代语句:
1、do{statement}while (expression);
2、while(expression) statement
3、for(initialization;expression;post-loop-expression)statement
4、for(property in expression) statement
另外,还有break,continue等语句。它们与java,C#中没区别。
with(expression) statement;
switch(expression){
case value:statement
break;
}
函数:function functionName(arg0,arg1...argN){
statement }
注意:ECMAScript中的函数不能重载,ECMAScript支持闭包。
//********************
工厂方式:(经典方式)

function showColor()...{
alert(this.color);
}

function createCar(sColor,iDoors,iMpg)...{
var oTempCar=new Object;
oTempCar.color=sColor;
oTempCar.doors=iDoors;
oTempCar.mpg=iMpg;
oTempCar.showColor=showColor;
return oTempCar;
}
var car1=createCar("red",4,23);
var car2=createCar("blue",3,25);
car1.showColor(); //outputs "red"
car2.showColor(); //outputs "blue"
混合工厂方式:

function Car()...{
var oTempCar=new Object;
oTempCar.color="red";
oTempCar.doors=4;
oTempCar.mpg=23;
oTempCar.showColor=function()...{
alert(this.color);
}
return oTempCar;
}
//使用时:
var car=new Car();

本文概述了ECMAScript的基础语法,包括关键字、保留字、原始类型、字符串字面量及基本语句等核心概念,并通过实例展示了如何创建对象和定义函数。

1171

被折叠的 条评论
为什么被折叠?



