码迷,mamicode.com
首页 > 编程语言 > 详细

《饿了么大前端 Node.js 进阶教程》—Javascript 基础问题—引用传递

时间:2017-05-02 19:42:08      阅读:379      评论:0      收藏:0      [点我收藏+]

标签:else   node.js   nod   array   引用类型   isarray   hub   exp   node   

《饿了么大前端 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,因为是引用类型,比较的是地址;

 

《饿了么大前端 Node.js 进阶教程》—Javascript 基础问题—引用传递

标签:else   node.js   nod   array   引用类型   isarray   hub   exp   node   

原文地址:http://www.cnblogs.com/sungg/p/6797604.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!