call()和apply()
//这两个对象都是函数对象的方法,需要通过函数对象来调用
//apply()方法需要将实参封装到一个数组中统一传递
//arguments()方法
// arguments是实参的对象是一个类数组对象
//arguments.length获取实参的长度
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script type="text/javascript">
//call()和apply()
//这两个对象都是函数对象的方法,需要通过函数对象来调用
//apply()方法需要将实参封装到一个数组中统一传递
function fun(){
alert('我是fun函数');
var obj ={
name:'obj',
sayName:function(){
alert(this.name);
}
};
};
// fun.call(obj,2,3);
// fun.apply(obj,[2,3]);
//arguments()方法
// arguments是实参的对象是一个类数组对象
//arguments.length获取实参的长度
function fun(){
console.log(arguments.length);
}
fun('hello',true);
//date对象在js中表示日期
//输出当前时间
// document.write(Date())
//输出指定日期
var d = new Date(2022,3,26,12,33,0);
// document.write(d)
d1 = d.getDate();//获取几号
console.log(d1);
d2 = d.getDay();//获取一周中的第几天
console.log(d2);
d3 = d.getMonth();//获取月份
console.log(d3)
d4 = d.getTime()//获取时间戳
console.log(d4/1000/60/60/24/365);
//设定日期
var myDate = new Date();
document.write(myDate.setDate(myDate.getDate()+5));//当前日期加5天
//math工具类,属于一个工具类不需要创建可以直接用
console.log(Math.round(4.7));
// 常量有e,pi
//abs计算一个数的绝对值
console.log(Math.abs(-99));
//向上求余
console.log(Math.ceil(1.1));
//向下求余
console.log(Math.floor(1.9));
//四舍五入
console.log(Math.round(2.5));
//最大数
console.log(Math.max(1,2,344,567));
//3的2次幂
console.log(Math.pow(3,2));
//随机数默认生成0-1之间的数字
console.log(Math.random()*10);
console.log(Math.floor(Math.random()*11));
//包装类,有三个包装类,通过这3个包装类可以将基本数据类型转换成对象
//字符串相关方法
var str = 'hello atguigu';
console.log(str[1]);//打印字符串的精确位置
var res = str.charAt(0);
console.log(res);//返回指定位置的字符
rest = str.charCodeAt(1);//返回字符串编码
console.log(rest);
resu = String.fromCharCode(72);//返回unicode代表的字符串
console.log(resu);
resu = str.concat('嘿嘿嘿');//连接一个或者多个字符
console.log(resu);
resul = str.indexOf('h');//检索一个字符在一串字符中的位置
console.log(resul);
result =str.lastIndexOf('h');//检索一个字符在字符串的位置,反向
console.log(result);
result1 = str.split(',');//拆分字符串为数组,参数是分隔符
console.log(result1);
result2 = str.toUpperCase();//将字符串转化成大写字母
console.log(result2);
result3 = str.toLowerCase();//字符串转换成小写字母
</script>
</body>
</html>