0

How to extend object in gulp without installing npm?

var a = {a: 1};
var b = {b: 2};
var c = extend({}, a, b, {c:3});

c is {a: 1, b: 2, c: 3}
6
  • Using loop, copying key-value pairs from a and b to c? Commented Mar 27, 2015 at 14:03
  • I don't wanna write extend function for every gulp file Commented Mar 27, 2015 at 14:30
  • Can you clarify the question? At face this has nothing to do with gulp or npm. Are you asking how to extend an object's properties in plain Javascript? That's very well documented. Commented Mar 27, 2015 at 16:10
  • I'm wondering if there any utility available in gulp, which could extend objects like jQuery.extend or angular.extend or npm extend. I know that the same feature could be called in grunt by grunt.util._.merge. Commented Mar 27, 2015 at 19:50
  • That's because grunt includes Lodash, you can also do this in your gulpfile, but you'll have to get Lodash first Commented Mar 28, 2015 at 0:50

1 Answer 1

1

Not that I know of. I would recommend that you use object-assign, a forward compatible module that will delegate to the ES6 Object.assign if available. It's extremely lightweight at 26 lines (as of this writing).

var assign = require('object-assign');

var a = {a: 1};
var b = {b: 2};
var c = assign(a, b, {c:3});

console.log(c);

// => {a: 1, b: 2, c: 3}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.