[英]i got undefined when i consoled console.log
when i consoled err.kind i got value for it but when i set (error = { ...err };) then i did console i had undefined in my console ?!当我安慰 err.kind 我得到了它的价值但是当我设置 (error = { ...err };) 然后我做了控制台我在我的控制台中未定义?!
module.exports = (err,req,res,next)=>{
err.statusCode = err.statusCode || 500 ;
err.state = err.state ||"error";
if(process.env.NODE_ENV === "development"){
console.log(err.name)
DevError(err,res);
}
else if (process.env.NODE_ENV !== "development"){
let error = { ...err };
if(error.kind === "CastError") error= wrongID(error)
console.log(error.kind)
cliError(error,res);
}
}
This is a rest destructuring issue where only the enumerable properties are getting copied over.这是一个剩余的解构问题,其中只有可枚举的属性被复制。 Search for "Rest in Object Destructuring" here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
在此处搜索“Rest in Object Destructuring”: https : //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment
Consider this:考虑一下:
const example1 = { a: 1 };
// this creates a non-enumerable property "b"
Object.defineProperty(example1, 'b', { value: 2 });
const example2 = { ...example1 };
console.log(example1.a);
// 1
console.log(example1.b);
// 2
console.log(example2.a);
// 1
console.log(example2.b);
// undefined
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.