Code Monkey home page Code Monkey logo

Comments (3)

schnittstabil avatar schnittstabil commented on July 23, 2024

Mhm, doesn't concatArrays work for you?

const result = mergeOptions.call({concatArrays: true}, {}, {a:[3]}, {a:[1,2]});
// { a: [3, 1, 2] }

That could support multiple different methods (which could even be user-extendible), with the default being the current behavior of right-most replacement as an object value.

Can you elaborate this and give some examples? Maybe you are on the track of something.

from merge-options.

shellscape avatar shellscape commented on July 23, 2024

@schnittstabil man, I completely missed that option, thanks for pointing it out.

So in scenarios where options need to be passed to a method that typically operates on all ...args, it's typically easier on users and sanity checking to provide a factory method which accepts only an options argument and returns an instance of the method which is scope-configured according to the options passed to the factory. In that way, mergeOptions.set({ concatArray: true }) would return an instance of mergeOptions which could then be called such like mergeOptions(obj1, obj2, ...) without having to remember to have the first object be an options object. It also provides reuse of that configured instance without having to manually wrap mergeOptions.

from merge-options.

schnittstabil avatar schnittstabil commented on July 23, 2024

If I understand you correctly, you can already accomplish that via Function.prototype.bind():

const mergeOptions = require('merge-options');

const merge = mergeOptions.bind({concatArrays: true})
merge({}, {a:[3]}, {a:[1,2]});
// { a: [ 3, 1, 2 ] }

from merge-options.

Related Issues (15)

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.