js语法

 

<script  type="text/javascript">
$(document).ready(function(){
	
//对象	
	//对象直接量
	var point={y:3,"z":9};
	
	//关联数组方式
	point["x"]=1;
	
	//对象属性方式
	point.d=1;
	
	对象属性枚举
	for(porty in point)
	 alert(porty+"="+point[porty]);
	 
	// 查看数据类型
	 alert(typeof(point));
//数组
	//数组直接量
	var array1=[[1,2,3],[4,5,6]];	
	alert(array1[1][1]);
	
	//数组对象
	
	
	var array2=new Array(10);
	array2[2]="x";
	alert(array2.length);
	for(value in array2)
	 alert(array2[value]);
	 
//数组方法
	var array3=["1","2","x","sda",3];
	
	//Strig join();
	
	alert(array3.join("+"));1+2+x+sda+3
	alert(array3.toString());1,2,x,sda,3 
	
	//Array reverse();
	
	array3.reverse();
	alert(array3.join("+"));3+sda+x+2+1 
	
	//concat(arg1,arg2,...)连接方法
	
	array3.concat(0,["k",9,["jkdk"] ]);
	alert(array3.concat(0,["k",9,["jkdk"] ]).join());
	
	//slice(m,n)截取子串[)
	alert(array3.slice(1,3).join());//slice(+n,+n)ingdex=0截取子串[)-->2,x
	alert(array3.slice(-3,-1).join());//slice(-n,-n),index=1截取子串[)-->x,sda
	alert(array3.slice(1,-2).join());//slice(+n,+n)ingdex=0截取子串[)-->2,x
	
	//splice(start,len,arg1,arg2....)插入、删除start:起始删除位置,len:删除长度,arg1、arg2...插入参数
	
	//删除
	alert(array3.splice(1,2).join());//返回被删除的数组 2,x
	alert(array3.join());//1,sda,3 
	array3.splice(1,0,"charu");//插入
	alert(array3.join()); 
	
//Arguments内置对象(存放参数	args(3);
	
	//匿名函数递归arguments.callee
	alert(jie_cheng(3));
	
//函数参数类型检查
	checkArgType([1,'a',5,2]);
//函数的方法
	call()
	maxValue=Math.max(11,2,3,4);	
	
	maxValue=Math.max.call(Math,2,3,4);	
	alert(maxValue);
	apply()
	minValue=Math.min.apply(Math,[1,3,7]);
	alert(minValue);
	
//对象
	function Rectangle(width,height)
	{
		this.width=width;
		this.height=height;
	}
	//调用原型对象
	Rectangle.prototype.area=function(){return this.width*this.height;}
	
	var rect=new Rectangle(2,3);
	alert("rect.width:"+rect.width);	
	alert("rect.area:"+rect.area());
	
	//类属性、方法(静态属性、静态方法)
	
	Rectangle.ZC=function(rect){return (rect.width+rect.height*2)}
	alert(Rectangle.ZC(rect));
	
	
	//继承
	function PositionRectangle(x,y,width,height)
	{
		Rectangle.call(this,width,height);或者
		this.superClass(width,height);
		this.x=x;
		this.y=y;
	}
	PositionRectangle.prototype=new Rectangle();
	
	var prect=new PositionRectangle(0,0,2,3);
	alert("prect.area:"+prect.area());
});
//Arguments内置对象(存放参数)	
	function args(x)
	{
		arguments[0]=2
		alert(x);
	}
	
	//匿名函数递归arguments.callee
	jie_cheng=function(x){
				if(x<=1)  return 1 ;
				return x*arguments.callee(x-1);
			  }
//函数参数类型检查
	function  checkArgType(args)//求array数组之和
	{
		sum=0;
		if(args instanceof Array || (args && typeof args=='object' && length in args))
		{
			for(i=0;i<args.length; i++)
			{
				alert(typeof args[i]);
				if(!args[i]) continue;
				if(typeof args[i]=="number")
					sum=sum+args[i];
				else throw new Error("存在不是数字的元素");
			}
			alert(sum);
		}
			
		else
		throw new Error("参数不是数组");
	}	
	
	//类、超类、继承	
	//超类1
	function Rectangle(width,height)
	{
		this.width=width;
		this.height=height;
	}
	Rectangle.prototype.area=function(){
		return this.width*this.height;
	}
	//超类的派方法生1
	function PostionRectangle(x,y,width,height)
	{
		Rectangle.call(this,width,height);
		this.x=x;
		this.y=y;
	}
	PostionRectangle.prototype=new Rectangle();//Rectangle的实例
	pr=new PostionRectangle(1,2,3,5);
	
	alert(Object.prototype.toString.apply(pr));	
	

</script>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值