变量在javascript中不被识别为变量(Variable not being recognized as variable in javascript)

编程入门 行业动态 更新时间:2024-10-26 10:29:22
变量在javascript中不被识别为变量(Variable not being recognized as variable in javascript)

有人能够在下面的代码中告诉我我错在哪里吗? 出于某种原因,'contact.name'中的第一个'联系人'看不到变量。

var newContact = new Contact({ contact.name = req.body.name, contact.email = req.body.email, contact.number = req.body.number });

Would someone be able to tell me where I am wrong in the following code? For some reason the first 'contact' in 'contact.name' is not seen a variable.

var newContact = new Contact({ contact.name = req.body.name, contact.email = req.body.email, contact.number = req.body.number });

最满意答案

你想做这样的事吗?

var newContact = new Contact({ contact: { name: req.body.name, email: req.body.email, number: req.body.number } });

我们需要了解有关Contact类构造函数及其参数的更多信息,以确保传递的参数的格式正确。

拥有这样的参数实际上更有意义:

var newContact = new Contact({ name: req.body.name, email: req.body.email, number: req.body.number });

Did you want to do something like this?

var newContact = new Contact({ contact: { name: req.body.name, email: req.body.email, number: req.body.number } });

We need to know more about the Contact class constructor and its parameters in order to make sure that the passed arguments are in the correct form.

It would actually make more sense to have the arguments like this:

var newContact = new Contact({ name: req.body.name, email: req.body.email, number: req.body.number });

更多推荐

本文发布于:2023-07-26 02:12:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1269568.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   不被   javascript   variable   Variable

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!