javascript - Object spread vs. Object.assign

Pubblicato il: 13 aprile 2024
sul canale di: Code Samples
184
4

Let’s say I have an options variable and I want to set some default value.
What’s is the benefit / drawback of these two alternatives?
Using object spread
options = {...optionsDefault, ...options};

Or using Object.assign
options = Object.assign({}, optionsDefault, options);

This is the commit that made me wonder.
here: https://github.com/tc39/proposal-obje...
spread defines properties, whilst Object.assign() sets them: http://2ality.com/2016/10/rest-spread...


In questa pagina del sito puoi guardare il video online javascript - Object spread vs. Object.assign della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Code Samples 13 aprile 2024, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 184 volte e gli è piaciuto 4 spettatori. Buona visione!