Lodash _.mixin() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Util

Definition

Adds all own enumerable string-keyed function properties of source to the destination object (defaults to Lodash). If the destination is a function, methods are added to its prototype as well. Part of Lodash Util since 0.1.0 (stable — not deprecated).

Pass the arguments shown below. Prefer modular imports when you only need this helper.

Syntax

Call _.mixin. Start with this line.

Lodash
_.mixin([object=lodash], source, [options={}])
CallWhat it does
_.mixin([object=lodash], source, [options={}])Primary signature.
_.mixin(...)Call the util helper.

Prefer import mixin from "lodash/mixin" when you want a smaller bundle.

Library declarations
Lodash
_.mixin([object=lodash], source, [options={}])

Parameters

ParameterDescription
objectOptional. Destination (default: Lodash). Functions also get prototype methods.
sourceRequired. Object whose own function properties are copied
options.chainOptional. Default true — keep mixins chainable

Return Value

Return ValueDescription
*The destination object

Lodash Examples

Example 1 — Official: vowels Mixin

Add a custom helper and call it directly or through a chain.

Lodash
function vowels(string) {
  return _.filter(string, function (v) {
    return /[aeiouy]/i.test(v);
  });
}

_.mixin({ 'vowels': vowels });

_.vowels('fred');
// → ['e']

_('fred').vowels().value();
// → ['e']
Try It Yourself

How It Works

  1. Define. vowels keeps letters that match the vowel regex.
  2. Mixin. _.mixin({ vowels }) attaches it to Lodash.
  3. Direct call. _.vowels('fred') → ['e'].
  4. Chain. With default chain: true, unwrap with .value().

Example 2 — chain: false

Disable chaining so a wrapped call returns the raw value.

Lodash
function vowels(string) {
  return _.filter(string, function (v) {
    return /[aeiouy]/i.test(v);
  });
}

_.mixin({ 'vowels': vowels }, { 'chain': false });

_('fred').vowels();
// → ['e']  (already unwrapped — no .value())
Try It Yourself

How It Works

  1. Same helper. Still filters vowels from the string.
  2. Option. { chain: false } marks the mixin non-chainable.
  3. Unwrap. _('fred').vowels() returns ['e'] directly.
  4. Use. Prefer this when the next step needs a plain array, not a wrapper.

Example 3 — Custom Destination Object

Extend your own utils object instead of the global _.

Lodash
var appUtils = {};

_.mixin(appUtils, {
  greet: function (name) {
    return 'Hello, ' + name + '!';
  }
});

appUtils.greet('Ada');
// → 'Hello, Ada!'
Try It Yourself

How It Works

  1. Target. First argument is appUtils, not Lodash.
  2. Copy. Own function greet is added to that object.
  3. Call. Use appUtils.greet(...) — _ stays untouched.
  4. Return. _.mixin returns appUtils for further chaining if needed.

Example 4 — Isolate with runInContext

Extend a private Lodash copy so the global _ stays clean.

Lodash
var lodash = _.runInContext();

lodash.mixin({
  double: function (n) {
    return n * 2;
  }
});

lodash.double(21);
// → 42

typeof _.double;
// → 'undefined'  (global _ was not mixed)
Try It Yourself

How It Works

  1. Fresh copy. _.runInContext() returns a private Lodash.
  2. Mixin there. double lives only on that copy.
  3. Call. lodash.double(21) → 42.
  4. Safe. Global _ has no double — avoids plugin clashes.

Browser & Runtime Support

_.mixin is a Lodash Util helper since 0.1.0. It runs anywhere the full Lodash build runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 0.1.0+

_.mixin()

Available in [email protected] full builds. Modular per-method imports do not include mixin alone — use the full build or a custom Lodash build when you need it.

100% With Lodash 0.1+
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.mixin Lodash 0.1.0+

Bottom line: Safe for production once the full Lodash build is loaded. Prefer _.runInContext() before mixing in shared or library code.

Frequently Asked Questions

_.mixin([object=lodash], source, [options]) copies every own enumerable string-keyed function from source onto object. By default object is Lodash itself, so helpers become _.yourFn() and can join chains when options.chain is true.
When chain is true (default), mixed-in methods stay wrapped in Lodash chains so you can call .value(). When chain is false, a chained call returns the raw result immediately.
Yes. Pass the destination first: _.mixin(myUtils, { greet(name) { return 'Hi ' + name; } }). Returns the same object. Global _ is not changed.
Mixing into the shared _ can clash with other code or overwrite built-ins. _.runInContext() gives a fresh Lodash copy you can extend safely.
No. Only own enumerable function properties on source are added. Nested non-function values are skipped.
No. It is a stable Lodash Util method since 0.1.0. Prefer modules for most apps; use mixin when you want Lodash-style extensions or chaining.

Next: _.noConflict()

Revert _ to its previous owner and keep a Lodash reference.

_.noConflict() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

10 people found this page helpful