angular.copy()和JSON.parse之间的差异(JSON.stringify())? [英] Differences between angular.copy() and JSON.parse(JSON.stringify())?

查看:412
本文介绍了angular.copy()和JSON.parse之间的差异(JSON.stringify())?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能解释angular.copy()和JSON.parse之间的差异(JSON.stringify())?是否有?你会推荐使用?是angular.fromJson(angular.toJson())相同JSON.parse(JSON.stringify())?
结果
结果
刚才说了,我读过最优雅的方式来克隆JavaScript对象了解JSON.parse(JSON.stringify())和 angular.copy ()为参考angular.copy ()。

Can someone explain the differences between angular.copy() and JSON.parse(JSON.stringify())? Are there any? What you will recommend to use? Is angular.fromJson(angular.toJson()) the same as JSON.parse(JSON.stringify())?

Just to mention, I've read Most elegant way to clone a JavaScript object for JSON.parse(JSON.stringify()) and angular.copy() reference for angular.copy().

推荐答案

什么 JSON.parse(JSON.stringify())不会复制:


  • 功能

  • 具有特殊重presentation,如日期的任何对象(将被复制,但并不像日期

  • 与值未定义的属性

  • functions
  • any object that has a special representation, like Date (it will get copied but not as Date)
  • properties with the value undefined

angular.fromJson(angular.toJson())是除了基本相同 angular.toJson()忽略了由内部角使用的属性(那些开始 $ )。

angular.fromJson(angular.toJson()) is basically the same except that angular.toJson() omits properties that are used by Angular internally (those starting with $$).

这篇关于angular.copy()和JSON.parse之间的差异(JSON.stringify())?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆