angular.copy()和JSON.parse之间的差异(JSON.stringify())?差异、copy、angular、JSON

2023-09-14 00:12:11 作者:噤語

有人能解释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 $$).