内部对象
标准对象
type of 标注类型
typeof 123
"number"
typeof '123'
"string"
typeof NaN
"number"
typeof []
"object"
typeof {}
"object"
typeof Math.abs
"function"
typeof undefined
"undefined"
typeof true
"boolean"
Date日期对象
/* Date对象*/
var now = new Date();
now.getFullYear();//年
now.getMonth();//月 0-11
now.getDate();//日
now.getDay();//星期几
now.getHours();//时
now.getMinutes();//分
now.getSeconds();//秒
now.getTime();//时间戳 全世界统一 1970 1.1 0:00:00 毫秒数
console.log(now);
console.log(now.toLocaleDateString());
console.log(now.toDateString());
console.log(new Date(1616383187381));//时间戳转为时间
json对象(前后端)
// MongoDB (bson )
轻量级数据交换格式 任何 js支持的类型
格式:
1.对象 {}
2.数组 []
3.所有键值对 key:value
{}里面是单引号外面用双引号 里面是双引号外面是单引号
/*json*/
var user = {
name:"zp",
age:20,
sex:'男'
}
// 对象转换为json 字符串 {"name":"zp","age":20,"sex":"男"}
var jsonUser = JSON.stringify(user)
// 对象转换为json字符串 参数为json字符串
var obj = JSON.parse('{"name":"zp","age":20,"sex":"男"}')
JSON 和js 对象区别:
var obj = {a:'hello',b:'hi'}
var json = '{"a":"hello","b":"hi"}'
Ajax
不重新加载整个页面的情况下,可以与服务器交换数据并更新部分网页内容
原生js 写法 xhr异步请求
jQuery 封装好的方法
axios 请求
面向对象编程
类:模板
对象:具体的示例
proto
var user = {
name:" aa ",
age: 3 ,
run: function () {
console.log(this.name +" "+ "running");
}
};
var xiaoming = {
name: "xioaming"
};
xiaoming.__proto__= user ;
class 继承
定义一个类,属性,方法
class Student{
constructor(name) {
this.name=name
}
hello(){
alert("hello")
}
}
var xiaoming = new Student("xiaoming");
var xiaohong = new Student("xiaohong");
继承
class Student{
constructor(name) {
this.name=name
}
hello(){
alert("hello")
}
}
class SmallStudent extends Student{
constructor(name,Class) {
super(name);
this.Class=Class;
}
getHello(){
alert("我是小学生");
}
}
var xiaoming = new Student("xiaoming");
var xiaohong = new SmallStudent("xiaohong");
原型链
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-NFatg7RP-1616422350425)(C:\Users\asus\AppData\Roaming\Typora\typora-user-images\image-20210322221127219.png)]