简体   繁体   English

JavaScript中的单个冒号作为变量(不是对象文字)的前缀

[英]Single colon in JavaScript as a prefix to a variable (not object literal)

In Chrome you can do: 在Chrome中,您可以执行以下操作:

date = new Date();

and then in the console you can do: 然后在控制台中,您可以执行以下操作:

hour:date.getHours();

What is this called? 这个叫什么? Where else does it work? 还有什么用呢?

I saw this in the follow code: 我在以下代码中看到了这一点:

showDateTimePicker(date, callback) {
    date = date || new Date();
    var options = {
        ...this.props,
        year:date.getFullYear(),
        month:date.getMonth(),
        day:date.getDate(),
        hour:date.getHours(),
        minute:date.getMinutes()
    };
    RCTDateTimePicker.showDateTimePicker(options, function (year, month, day, hour, minute) {
        date.setFullYear(year);
        date.setMonth(month);
        date.setDate(day);
        date.setHours(hour);
        date.setMinutes(minute);
        callback(date);
    });
}

hour:date.getHours(); and var options = {hour:date.getHours()}; var options = {hour:date.getHours()}; are two very different statements. 是两个截然不同的陈述。

The former is a label which is designed so that when you have nested loops and want to break or continue from one of them, you can specify which. 前者是一个标签 ,其设计目的是使您在具有嵌套循环并希望从其中一个循环中breakcontinue ,可以指定其中一个。 Putting it before a function call is useless. 将其放在函数调用之前是没有用的。

The latter is an object initialiser which allows you to specify the name and values of properties on a new object. 后者是一个对象初始化程序 ,它允许您指定新对象上属性的名称和值。

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

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