Answer the question
In order to leave comments, you need to log in
Why is the object overwritten?
Faced a problem and I can not understand why the object is overwritten.
For example, there is a file with a default object
schema.js
schema = {
"price": {
"min": 0,
"max": 99999
}
};
module.exports = schema;
var extend = require('extend');
var schema = require('./application/config/schema');
var used = {
"price": {
"min": 100,
"max": 2000
}
};
var clean = extend(true, schema.search, used);
console.log(schema);
price: { min: 100, max: 2000 }
Answer the question
In order to leave comments, you need to log in
As far as I understand, here it is necessary to create a clone of the object in order not to change the original, apparently something like this:
You can also use Object.assign instead of npm extend:console.log( Object.assign({}, schema, used) )
Why do extend
you start using schema.search
and not schema
?
It's very good to try this:
What do you need to get as an output?
The official documentation says
Keep in mind that the target object will be modified, and will be returned from extend().
The target object will be changed and will be returned as the result of extend()
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question