Answer the question
In order to leave comments, you need to log in
How to correctly shift the fields of one object to another?
There is a condition object and an error object:
const error = new Error();
const someObject = {
message: 'Fail',
count: 3,
};
error = { ...error, ...someObject }
, the error object ceases to be an error, but becomes a normal object
Answer the question
In order to leave comments, you need to log in
let error = new Error('hello');
const someObject = {
message: 'Fail',
count: 3,
};
console.log(error.message) // hello
error = {...error, ...someObject};
console.log(error.message) // Fail
console.log(error.count) // 3
const someObject = {
message: 'Fail',
count: 3,
};
class CustomError extends Error {
constructor(obj) {
super();
for ( let key in obj ) {
this[key] = obj[key]
}
}
}
let error = new CustomError(someObject);
console.log(error) // объект ошибки
console.log(error.message); // Fail
console.log(error.count); // 3
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question