【问题标题】:Can I use colons as variable names in Javascript?我可以在 Javascript 中使用冒号作为变量名吗?
【发布时间】:2013-09-16 14:39:43
【问题描述】:

有没有办法可以使用带有冒号的变量作为变量名?我需要这个用于 facebook,我必须将它作为参数传递:

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

例如。 我该怎么做呢?当我尝试时,它并没有完全奏效..

【问题讨论】:

    标签: javascript facebook facebook-graph-api facebook-opengraph


    【解决方案1】:

    试试这个:

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

    请注意,这些不是“变量”,它们是对象属性名称。属性名称可以是任何有效的 JS 字符串,如果你把它们放在引号中的话。

    有关更多信息,请参阅 MDN 的文章Working With Objects

    【讨论】:

      猜你喜欢
      • 2019-02-14
      • 2012-08-05
      • 2011-10-14
      • 1970-01-01
      • 2017-02-14
      • 1970-01-01
      • 2017-02-27
      • 2023-03-24
      • 1970-01-01
      相关资源
      最近更新 更多