简体   繁体   English

当我安慰 console.log 时,我得到了未定义

[英]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.

相关问题 Redux-Toolkit 中的 RTK 查询返回未定义的数据,当我 console.log 显示在控制台中的数据时 - RTK Query in Redux-Toolkit is returning data of undefined, when I console.log the data it appears in console 当我console.log req.files.path时,express-formidable返回“ undefined” - express-formidable returns “ undefined” when i console.log req.files.path 当我在console.log(req.user)时,它总是未定义,虽然我是console.log(req),它显示了关于此会话的所有信息 - When I console.log(req.user), it allways undefined although I console.log(req), it show all infor about this session web 抓取 function 返回“未定义”,但在我使用 console.log 时有效 - web scraping function returns “undefined” but works when I use console.log Object 是未定义的,但是当我 console.log 他们总是“有效” Node.js 表达 - Object is undefined, but when I console.log them always "works" Node.js express 未定义而 console.log() - Undefined while console.log() Return 给了我未定义但 console.log 给出了我需要的答案 - Return is giving me undefined but console.log give the answer I needed 如何与.on同时调用console.log和console.log()? - How can I invoke console.log and console.log() simultaneously with .on? 单击提交时,我无法使用 console.log 在终端中显示用户名和密码 - I cant show the username and password in terminal with console.log when i click the submit 我得到一个<buffer... />当我使用 Websocket 用户发送的 console.log 消息时 - I get a <Buffer.../> when I console.log message sent by user using Websocket
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM