基本类型的传递是复制一个新的值,会单独开发出一块新的内存

    1. var a = 1
    2. function show() {
    3. var b = a + 100
    4. console.log(b) // 101
    5. }
    6. console.log(show(a)) // 1

    image.png
    引用类型的传递是栈地址发生改变, 多个引用类型的地址会指向同一个堆内存

    1. var a = {name: 'qihuanran', age: 13}
    2. function show(a) {
    3. a.age = 100
    4. console.log(a.age) // 100
    5. }
    6. show(a)
    7. console.log(a) // 100

    image.png
    遍历对象

    1. var a = {name: 'qihuanran', age: 123}
    2. for (let key in a) {
    3. console.log(a[key]) // 'qihuanran', '123'
    4. }

    展开对象
    image.png
    image.png
    查询对象中是否包含某个元素,不包含原形父级
    Object.hasOwnProperty(‘name’)
    查询对象中是否包含某个元素,包含原形父级

    1. console.log('concat' in Object)
    2. // true

    指定原形继承

    1. let a = {name: 'qihuanran'}
    2. let b = {age: 12}
    3. Object.setPrototypeOf(a, b)
    4. console.log(a.age) // 12
    5. console.log('age' in a) // true