1.数据类型分类 ( 掌握 )
- 基本类型
- number: 数值
- string: 字符串
- boolean: 布尔
- undefined: 未定义
- null: 空
- symbol: 符号
- 引用类型
- Object: 对象
- Array: 数组
- Date: 日期
- Math: 数学
- Function: 函数
- Number: 数值
- String: 字符串
- Boolean: 布尔
- RegExp: 正则
2. 数据在内存中分配 ( 掌握 )
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-K7yujfwg-1681660774357)(C:\Users\admin\Desktop\内存分配.png)]
3. 数据拷贝 ( 掌握 )
-
基本类型
var b = a; //拷贝: a的值赋值给b
-
引用类型
-
浅拷贝
var user = { name: '1', age: 23 } #1. forin var userObj = {} for(const key in user){ userObj[key] = user[key] } #2. Object.assign var userObj = Object.assign({}, user) #3. 扩展运算符 var userObj = {...user}
-
深拷贝
var user ={ name: '2', age: 30, obj: { key: 90 } } #1.json两个核心方法 var userObj = JSON.stringify( user ) userObj = JSON.parse( userObj ) 小结: 缺点 时间对象 ===> 字符串 正则对象 ===> 空对象 函数&undefined ===> 丢弃掉 构造函数 ===> 丢掉constructor 循环语句 ===> 报错 NaN ===> null #2.递归函数
-
4.数据类型检测 (掌握)
-
typeof
#1.检测基本类型 typeof 12 //number typeof '' //string typeof true //boolean typeof undefined //undefined typeof null //object typeof Symbol() //symbol
-
instanceof
#语法 实例对象 instanceof 构造函数 #理解 实例对象是否由构造函数构造 #举例 arr instanceof Array #检测数组方法 Array.isArray(数组)
-
Object.prototype.toString.call
#语法 Object.prototype.toString.call(数据) #结果 [Object 类型]
5.ES5继承 ( 了解 )
/* 寄生组合式继承 */
//父类
function Person(name){
this.name = name;
}
Person.prototype.show = function (){}
//子类
function Son(name, fill){
Person.call(this) //继承父类属性
this.fill = fill;
}
Son.prototype = Object.create(Person.prototype) //继承父类原型方法
Son.prototype.constructor = Son; //还原子类构造器
Son.prototype.eat = function (){}