Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/57.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Gruntjs grunt.init.config中引号的作用是什么_Gruntjs - Fatal编程技术网

Gruntjs grunt.init.config中引号的作用是什么

Gruntjs grunt.init.config中引号的作用是什么,gruntjs,Gruntjs,我有时在Grunfile中看到这一点: grunt.initConfig({ 'connect': { testserver: { options: { 为什么connect有引号?我尝试删除,但它仍然有效,所以我想知道为什么“连接”:{而不仅仅是连接:{ 是否有良好的惯例或其他惯例?或者这些是保留字?对象属性名称周围的引号可用于避免某些关键字或特殊符号,即JS解释器通常会将属性名称(如asdf+123)视为算术表达式,并在将其解析为对象时出错属

我有时在Grunfile中看到这一点:

grunt.initConfig({
    'connect': {
        testserver: {
            options: {
为什么connect有引号?我尝试删除,但它仍然有效,所以我想知道为什么“连接”:{而不仅仅是连接:{


是否有良好的惯例或其他惯例?或者这些是保留字?

对象属性名称周围的引号可用于避免某些关键字或特殊符号,即JS解释器通常会将属性名称(如asdf+123)视为算术表达式,并在将其解析为对象时出错属性键名称,但它会将“asdf+123”视为可用作属性键名称的字符串。有些人可能会在所有属性名称周围加引号以防万一,但我不确定为什么会特别在Grunt配置对象属性周围加引号。