首页 \ 问答 \ 语法错误在哪里(Where is the syntax error)

语法错误在哪里(Where is the syntax error)

我有这个代码,我试图在LocalHost上运行它。 我一直收到意外的令牌错误。 有谁知道为什么?

我想要做的是制作一个简单的API,它接受用户的输入并将它们保存到monogo数据库中。

var PodDoc = require('../models/pods.js');

module.exports = {
  save: save
}

function save(pod, callback){
  var podToSave = new PodDoc();
  podToSave.firstName = pod.firstName;
  podToSave.lastName = pod.lastName;
  podToSave.skills = pod.skills;
  podToSave.avatarUrl = pod.avatarUrl;
  podToSave.address = {
    address.number = pod.address.number; //This is where the Unexpected Token is
    address.lineOne = pod.address.lineOne;
    address.lineTwo = pod.address.lineTwo;
    address.postcode = pod.address.postcode;
  };
  podToSave.phoneNumbers = {
    podToSave.phoneNumbers.mobile = pod.phoneNumbers.mobile;
    podToSave.phoneNumbers.landline = pod.phoneNumbers.landline;
  }
  podToSave.save(function(err){
    if(err){
      console.log(err);
    } else {
      console.log("Cool!");
      callback();
    }
  })
}


I have this code and I'm trying to run it on LocalHost. I keep getting an unexpected token error. Does anyone know why?

What I'm trying to do is make a simple API that takes inputs from the user and saves them onto a monogo database.

var PodDoc = require('../models/pods.js');

module.exports = {
  save: save
}

function save(pod, callback){
  var podToSave = new PodDoc();
  podToSave.firstName = pod.firstName;
  podToSave.lastName = pod.lastName;
  podToSave.skills = pod.skills;
  podToSave.avatarUrl = pod.avatarUrl;
  podToSave.address = {
    address.number = pod.address.number; //This is where the Unexpected Token is
    address.lineOne = pod.address.lineOne;
    address.lineTwo = pod.address.lineTwo;
    address.postcode = pod.address.postcode;
  };
  podToSave.phoneNumbers = {
    podToSave.phoneNumbers.mobile = pod.phoneNumbers.mobile;
    podToSave.phoneNumbers.landline = pod.phoneNumbers.landline;
  }
  podToSave.save(function(err){
    if(err){
      console.log(err);
    } else {
      console.log("Cool!");
      callback();
    }
  })
}


原文:https://stackoverflow.com/questions/35159749
更新时间:2023-08-13 20:08

最满意答案

不,你做不到,老实说拥有这样的功能毫无意义。

如果您需要使用键和值动态分配一些数据,则可以使用字典:

Dictionary<string, RectangleShape> shapes = new Dictionary<string, RectangleShape>();
shapes.Add("matrix1_2", new RectangleShape( ... ));

然后你可以简单地阅读“变量”

shapes["matrix1_2"]

No, you can't, and it makes no sense honestly to have a feature like that.

If you need to dynamically assign some data with key and value, you could use an dictionary:

Dictionary<string, RectangleShape> shapes = new Dictionary<string, RectangleShape>();
shapes.Add("matrix1_2", new RectangleShape( ... ));

Then you can simply read the "variable" like

shapes["matrix1_2"]

相关问答

更多
  • 有一种使用场景,你可能需要这个。 我并不是暗示没有更好的方法或实现相同的功能。 这对于在错误,调试模式和其他类似情况下“转储”任意字典列表非常有用。 需要什么是eval()函数的反转: get_indentifier_name_missing_function() 它会将一个标识符名称('variable','dictionary'等)作为参数,并返回一个包含标识符名称的字符串。 考虑以下目前的状况: random_function(argument_data) 如果将一个标识符名称('function ...
  • 这在C中是不可能的。 查看此问题以获取更多详细信息。 如何返回变量名并指定c中返回的变量的值 引用Wichert的话,“我建议你重新考虑你想要解决的问题,并检查是否有更好的方法来解决它。 也许使用数组,地图或哈希表可能是一种适合您的替代方法。 This is simply not possible in C. Check out this question for more details. How to return a variable name and assign the value of the ...
  • 将其写入数组或对象 var arr = {}; arr['new' + 'variable'] = 'Hello World'; 然后 alert(arr['newvariable']); 要么 alert(arr.newvariable); Write it into an array or object var arr = {}; arr['new' + 'variable'] = 'Hello World'; then alert(arr['newvariable']); or alert( ...
  • 当你分配一个变量时,所有的解释器知道它包含的值,而不是它的名字。 所以当你循环你的值时, $corner将被设置为列表中的一个值。 除非您将该值作为$topLeft参数的值传递,否则它永远不会是topLeft ,这就是您的@if语句永远不会计算为true的原因。 如果使用默认值null而不是false,则可以简化很多操作: @mixin getCorner($topLeft: null, $topRight: null, $bottomRight: null, $bottomLeft: null) { ...
  • 您可以使用这样的宏: macro Name(arg) string(arg) end variablex = 6 a = @Name(variablex) julia> a "variablex" 信用(以及更多细节): 这个问答。 编辑:更多细节/说明:来自Julia 文档 : 宏将其参数作为表达式,文字或符号接收 因此,如果我们尝试使用函数(而不是宏)创建相同的效果,我们就会遇到问题,因为函数将其参数作为对象接收。 但是,对于宏, variablex (在此示例中)作为符号传递(例如,相 ...
  • 解决您的问题的最可能的解决方案是解决/更改/修复设计,这需要您为什么have a table which stores names of variables 。 The most likely solution to your problem is to address/change/fix the design that requires why you would have a table which stores names of variables.
  • 我不认为这对于局部变量是可能的,但是在使用反射的对象的成员变量中是可能的。 如果你走这条路线,MSDN知识库中有很多关于用反射设置属性的文章。 但是,反射是很昂贵的,因此可能有更好的方法来实现您的设计。 我想到的一种可能性是使用带字符串键的字典。 I don't think this is possible with local variables, but it's possible in member variables of an object using reflection. If you go ...
  • 不,你做不到,老实说拥有这样的功能毫无意义。 如果您需要使用键和值动态分配一些数据,则可以使用字典: Dictionary shapes = new Dictionary(); shapes.Add("matrix1_2", new RectangleShape( ... )); 然后你可以简单地阅读“变量” shapes["matrix1_2"] No, you can't, and it makes no ...
  • 请尝试以下方法: lst = ['spam', 'eggs', 'ham'] d = {} # empty dictionary for name in lst: d[name] = rat.readColumn(ratDataset, name) 不要将list用于您的标识符,因为它是类型标识符,您将掩盖其存在。 for循环可以直接迭代内部元素 - 不需要构造索引并使用它来激活列表。 d['spam']将是您的变量之一 。 虽然,也可以创建真正的变量名称,如spam , eggs , ham ...
  • function elem(name){ window[name]=document.getElementById(name); } 现在, elem('box'); 将创建全局变量box = document.getElementById('box'); 你可以使用。 示例代码
    box