Giter Site home page Giter Site logo

Comments (4)

schnittstabil avatar schnittstabil commented on July 19, 2024

@bobrenjc93 In my opinion that is the expected behavior, because we Recursively Object.assign():

deep_assign({a: [1]}, {a: []})

// should be similar to
{a: deep_assign([1], [])}

// which have to be the same as 
{a: Object.assign([1], [])}

(If Object {a: Array[1]} means {a: [1]})

This is consistent to the current undefined behavior.

from deep-assign.

bobrenjc93 avatar bobrenjc93 commented on July 19, 2024

I completely understand the recursive nature of this function. The question is what should be the base case. In my opinion, I think it only makes to recurse further if the value is a true object and not an array. In the event the value is not an object, the recursion should halt and behave the same way you'd expect a non recursive Object.assign for that particular value.

Perhaps it would be good to have the context under which this module was developed. I'm currently trying to use this module for a redux application and the behavior I described above was what I would expect in a recursive Object.assign module.

from deep-assign.

schnittstabil avatar schnittstabil commented on July 19, 2024

I think it only makes to recurse further if the value is a true object and not an array.

True Object is the crux of the matter: e.g Javascript also considers functions to be objects, and there seems no generally accepted definition for True Objects.

npm and bower contain myriad packages for merging/extending/… objects – most of them without a precise semantic. If you agree with me that Plain Objects are the one and only True Objects, schnittstabil/merge-options may meet your requirements.

As Object.assign does not distinguish Objects and Arrays I see no justification to do so in deep-assign.

from deep-assign.

bobrenjc93 avatar bobrenjc93 commented on July 19, 2024

Ah okay makes sense. merge-options is exactly what I need, I'll go use that. Thanks!

from deep-assign.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.