针对本地JS角JSON相关的功能

编程入门 行业动态 更新时间:2024-10-25 14:28:10
本文介绍了针对本地JS角JSON相关的功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 angular.toJson( obj, pretty ); angular.fromJson( json );

VS

JSON.stringify( obj ) JSON.parse( json )

我用原生的,但开始使用角度药粥一致性。其他原因使用那些?

I used to use native ones, but started to use angular ones for consistency. Any other reasons to use those?

推荐答案

我首先想到的是它的一些相关的测试目的(同样的情况下,使用$窗口,而不是窗口)。但寻找到源$ C ​​$ C后:的https:/ /github/angular/angular.js/blob/master/src/Angular.js#L977

My first thought was it's related to some test purposes(same case with using $window instead of window). But after looking into source code: github/angular/angular.js/blob/master/src/Angular.js#L977

function toJson(obj, pretty) { if (typeof obj === 'undefined') return undefined; if (!isNumber(pretty)) { pretty = pretty ? 2 : null; } return JSON.stringify(obj, toJsonReplacer, pretty); }

看起来像它的情况下,具有未定义的对象作为参数的简单包装。

Looks like it's a simple wrap for case with undefined object as param.

同为 fromJson : github/angular/angular.js/blob/master/src/Angular.js#L998

function fromJson(json) { return isString(json) ? JSON.parse(json) : json; }

所以,一般来说,它只是删除从应用code检查到框架code。

so, generally, it's just to remove that checking from app code into framework code.

更多推荐

针对本地JS角JSON相关的功能

本文发布于:2023-10-30 03:31:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1541638.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:功能   JS   JSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!