Hacker News new | ask | show | jobs
by hnben 1016 days ago
I don't like how it could result in surprises. e.g. you use it to update an array, but there are objects inside, which you accidentally modify.

I think these surprises could be reduced if you turn them into explicit parameters in the signature, e.g.

  export const updateWhere = (whereFn, updatefn, thing, recurseArray=true , recurseObjects=true)
1 comments

If `thing` contains any cycles then it will explode. E.g.

    const thing = {};
    thing.self = thing;
or

    const thing = [];
    thing.push(thing);
If this sounds far-fetched to you just know that all DOM elements have these circular references through (for example) parent / child references.

Also any non-enumerable properties that may have been defined on objects are lost.

Basically the function is only suitable for recently parsed JSON.

That's a great point