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相关的功能
发布评论