Date
<script>
//1.Date对象
var d1 = new Date();
//Thu May 02 2019 14:27:19 GMT+0800 (中国标准时间)
console.log(d1);
//转成2019/5/2 下午2:27:19
console.log(d1.toLocaleString());
//距离1900年经过年数
console.log(d1.getYear());//119
//获取当前纪年
console.log(d1.getFullYear());//2019
//获取一年中当前月份
console.log(d1.getMonth()); //4, 0-11
//获取一个月中的日期
console.log(d1.getDate());
//时
console.log(d1.getHours());
//分
console.log(d1.getMinutes());
//秒
console.log(d1.getSeconds());
//设置月份时,记得值为0-11
var d2 = new Date(2012,11,12,12,12,12);
console.log(d2.toLocaleString());//2012/12/12 下午12:12:12
//可以创建一个距离1970年经过的毫秒数
var d3 = new Date(1528980372222);
console.log(d3.toLocaleString())
</script>
Math
<script >
console.log(Math.random()) // [0,1) 随机数
console.log(Math.abs(-5)) //求取绝对值
console.log(Math.round(4.5)); //四舍五入
console.log(Math.ceil(3.1)); //天花板
console.log(Math.floor(3.9)); //地板
console.log(Math.pow(2,20)); //x的y次幂
console.log(Math.PI); //圆周率
</script>
String
<script type="application/javascript">
//var str = new String("aabbcc");
var str2 = "aabdcbc";
//console.log(str);
console.log(str2);
//转化大小写
console.log(str2.toUpperCase()); //大写
console.log(str2.toLowerCase()); //小写
//返回指定索引处的字母
console.log(str2.charAt(3));
//返回指定字母首次出现的索引
console.log(str2.indexOf("b"));
//返回指定字母最后一次出现的索引
console.log(str2.lastIndexOf("b"));
//截取子字符串,从x位置截取y个字符
console.log(str2.substr(2,3));
//截取子字符串,从x位置截到y位置
console.log(str2.substring(2,3));
//字符串length属性表示字符的个数
console.log(str2.length)
</script>
Object
<script type="application/javascript">
//1.在js中,我们可以使用Object对象来表述一个人
var obj = new Object();
//2.在js中,对象有个特点:属性可以动态的添加
//添加属性
obj.name = "laowang";
//修改属性的值
obj.name = "laoma";
//删除属性
delete obj.name;
function factory(name,age){
var obj = new Object();
obj.name = name;
obj.age = age;
return obj;
}
var per1 = factory("laowang",30);
console.log(per1.name);
var c1 = factory("benz",3);
console.log(c1.name);
//封装的人“类”
function Person(name,age){
this.name = name;
this.age = age;
}
var p1 = new Person("zhangsan",20);
console.log(p1.name);
console.log(p1.age);
var p2 = new Person("乔峰",25);
console.log(p2.name);
console.log(p2.age);
p2.skill = "降龙十八掌";
console.log(p1.skill);
console.log(p2.skill);
//为所有对象都添加属性
Person.prototype.money = 8888;
Person.prototype.like = ["吃饭","睡觉","打豆豆"];
Person.prototype.eat = function(){
alert("吃饭了,好开心!");
}
console.log(p1.money);
console.log(p2.money);
p1.like.push("写Java");
console.log(p1.like);
console.log(p2.like);
p1.money = 88888;
console.log(p1.money);
console.log(p2.money);
function Student(){
this.sno = Math.random();
}
Student.prototype = new Person("lisi",8);
var s1 = new Student();
console.log(s1.name);
console.log(s1.age);
console.log(s1.sno);
console.log(s1.money);
console.log(s1.like)
</script>