FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Update Object.assign() example to include modern spread operator alternative · Issue #705 · ryanmcdermott/clean-code-javascript · GitHub

Update Object.assign() example to include modern spread operator alternative #705

Description

Update Object.assign() example to include modern spread operator alternative

Summary

The current example for "Set default objects with Object.assign" should be updated to include the modern spread operator syntax as the preferred approach, while keeping Object.assign() for reference.

Current State

The documentation currently shows Object.assign() as the "good" example:

function createMenu(config) {
  let finalConfig = Object.assign(
    {
      title: "Foo",
      body: "Bar",
      buttonText: "Baz",
      cancellable: true
    },
    config
  );
  return finalConfig;
}

Proposed Change

Update the example to show the spread operator as the primary modern approach:

function createMenu(config) {
  const finalConfig = {
    title: "Foo",
    body: "Bar",
    buttonText: "Baz",
    cancellable: true,
    ...config  // Override defaults with user config
  };
  return finalConfig;
}

Suggested Implementation

Show both approaches with clear preference:

// Modern approach (recommended)
function createMenu(config) {
  const finalConfig = {
    title: "Foo",
    body: "Bar", 
    buttonText: "Baz",
    cancellable: true,
    ...config
  };
  return finalConfig;
}

// Alternative using Object.assign()
function createMenuAlternative(config) {
  const finalConfig = Object.assign(
    {
      title: "Foo",
      body: "Bar",
      buttonText: "Baz", 
      cancellable: true
    },
    config
  );
  return finalConfig;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL