java内置核心语言对象

内置核心对象
object   string    array     date    Math


一:对象

<script>
    	//对象的创建
		
		//方法一:
		var people=new Object();
		alert (people);						//[object Object]
		alert (typeof(people));					//object
		alert ( people instanceof Object);		//true  :相当于people是继承与Object
		
		//方法二:
		
		var people =new Object;
		alert (people);						//[object Object]
		alert (typeof(people));					//object
		alert ( people instanceof Object);		//true  :相当于people是继承与Object
		
		
		//方法三:
		
		var people ={
			//键:值
		name:"张三"
		}
		alert (people);						//[object Object]
		alert (typeof(people));					//object
		alert ( people instanceof Object);		//true  :相当于people是继承与Object
		
		
		//方法四:
		var people	= function(){
			
		}
		//万物皆对象
		var boy= new people();
		alert (people);						// function(){}
		alert (typeof(people));					//function
		alert ( people instanceof Object);		//true  :相当于boy是继承与Object    
		
		
		//对象的使用
		
		//一:
		var o=new Object;
		o.name="shuang";
		o["sex"]="man";
		alert (  o.name +"   "+ o.sex );//shuang  man
		
		//二
		var o1={
			name:'shuang',
			sex:'man'	
		}
		for( var i in o1){
			alert (i+":"+o1[i]);	//name :shuang   sex:  man 
		}
		alert(o1.hasOwnProperty("name"));//true
    
    </script>

二:数组

var arr=new Array(数组长度);
var arr=["","",""];

arr.sort();数组的排序
arr.join("-");链接
arr.push();在数组的最后一个位置添加,返回长度
arr.shift();在数组的第一个位置移除 返回该移除的元素
arr.pop();在数组的最后一个位置移除 返回该移除的元素
arr.unshift();在第一个位置添加;返回长度


Math.random();[0-1)
Math.floor( 数字 );//向下取整
Math.ceil( 数字 );//向上取整三


三:String

var str=new String()
var str="";

使用:

var str=document.title;
	function line(){
		str=str.substr(1,str.length)+str.substring(0,1);//substr:从1开始截取,截取str.length长度,不够就截取到最后一位;
<span style="white-space:pre">								</span>//substring:从0开始截取截取到1,包括0不包括1【0.1)
		document.title=str;
		console.log(str);
	}
	window.setInterval("line()",500);

四:Math

Math.random()   [0-1)
Math.floor(  int  );    向下取整
Math.ceil( int  );      向上取整
Math.round(  int  );    四舍五入

使用示例1:

<script>
    	var r,g,b;
		function color(){
			r=parseInt(Math.random()*256-1);
			g=parseInt(Math.random()*256-1);
			b=parseInt(Math.random()*256-1);
			return "rgb("+r+","+g+","+b+")";
		}
		function RandomColor(){
			document.getElementById("s1").style.color=color();
			document.getElementById("s2").style.color=color();
			document.getElementById("s3").style.color=color();
		}
		window.setInterval("RandomColor()",300);
    </script>
五:date


var date=new Date();
date.getFullyear();  获取年份
date.getMonth();    月份是从0开始的
date.getDate();
date.getDay();  星期,从星期天开始   0
使用实例:

<script>
	var arr=new Array(7);
	arr[0]="星期天";
	arr[1]="星期一";
	arr[2]="星期二";
	arr[3]="星期三";
	arr[4]="星期四";
	arr[5]="星期五";
	arr[6]="星期六";
function date(){
	
	
	var date=new Date();
	
	year=date.getFullYear();
	 month=date.getMonth()+1;
	 dat=date.getDate();
	day=date.getDay();
	hour=date.getHours();
	minu=date.getMinutes();
	
	sec=date.getSeconds();
	
	document.getElementById("a").innerHTML=year+"年"+month+"月"+dat+"日"+arr[day]+hour+":"+minu+":"+sec;
	}
	window.setInterval("date()",1000);//定时器,定时执行一个函数
	
</script>



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值