JavaScript变量进阶

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. 数据拷贝 ( 掌握 )

  1. 基本类型

    var b = a; //拷贝: a的值赋值给b
    
  2. 引用类型

    • 浅拷贝

      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 (){}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值