zoukankan      html  css  js  c++  java
  • 《饿了么大前端 Node.js 进阶教程》—Javascript 基础问题—引用传递

    《饿了么大前端 Node.js 进阶教程》地址:https://github.com/ElemeFE/node-interview

    1.如何编写一个 json 对象的拷贝函数

    function clone(obj){

      var result;

      if (Array.isArray(obj)) {

        result = [];

        obj.forEach((item) => {

          result.push(clone(item));

        });        

      } else if (typeof obj === 'object') {

        result = {};

        for (key in obj) {

          result[key] = clone(obj[key]);

        }

      } else {

        result = obj;

      }

      return result;

    }

    如果是Date或者RegExp之类的类型,就得另加判断了

    2.== 与 === 的区别

    == 是两边值相等,===是不仅值相等类型也要相等

    3.[1] == [1] 是 true 还是 false

    想都不要想,肯定是false,因为是引用类型,比较的是地址;

  • 相关阅读:
    ptmalloc内存分配和回收详解(文字版)
    HITCTF2018
    缓冲区溢出保护机制——Windows
    缓冲区溢出保护机制——Linux
    TAMUCTF
    反汇编简介
    apkg命令
    ubuntu基本命令
    ubuntu命令~
    apt-get用法
  • 原文地址:https://www.cnblogs.com/sungg/p/6797604.html
Copyright © 2011-2022 走看看