简体   繁体   English

我可以在冒号中使用冒号作为变量名吗?

[英]Can I use colons as variable names in Javascript?

Is there a way I can use variables with colons in them as variable name? 有没有一种方法可以将带有冒号的变量用作变量名? I would need this for facebook where I have to pass it on as parameters: 我需要在facebook上将其作为参数传递给我:

FB.api('me/namespace:action', 'POST',
{
  og:type : type,
  og:title : title,
  fb:explicitly_shared : true
});

for example. 例如。 How would I do this here? 我在这里怎么办? When I tried it didn't quite work out.. 当我尝试时,效果并不理想。

Try this: 尝试这个:

FB.api('me/namespace:action', 'POST',
{
  "og:type" : type,
  "og:title" : title,
  "fb:explicitly_shared" : true
});

Note that these aren't "variables", they're object property names. 请注意,这些不是“变量”,它们是对象属性名称。 Property names can be just about any valid JS string if you put them in quotes. 如果将名称放在引号中,则属性名称几乎可以是任何有效的JS字符串。

For more information see MDN's article Working With Objects . 有关更多信息,请参见MDN的文章“使用对象”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM