Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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
Javascript var lineColor={red:';blue';,blue:';red';}[lineColor]的意思是什么;_Javascript_Jquery_Arrays - Fatal编程技术网

Javascript var lineColor={red:';blue';,blue:';red';}[lineColor]的意思是什么;

Javascript var lineColor={red:';blue';,blue:';red';}[lineColor]的意思是什么;,javascript,jquery,arrays,Javascript,Jquery,Arrays,它交换/切换颜色。红色-->蓝色,蓝色-->红色 与 lineColor = 'blue'; lineColor = { red: 'red', blue: 'blue' }[lineColor]; // 'red' 它交换/切换颜色。红色-->蓝色,蓝色-->红色 与 lineColor = 'blue'; lineColor = { red: 'red', blue: 'blue' }[lineColor]; // 'red' 它交换/切换颜色。红色-->蓝色,蓝色-->红色 与 lin

它交换/切换颜色。红色-->蓝色,蓝色-->红色

lineColor = 'blue';
lineColor = { red: 'red', blue: 'blue' }[lineColor]; // 'red'

它交换/切换颜色。红色-->蓝色,蓝色-->红色

lineColor = 'blue';
lineColor = { red: 'red', blue: 'blue' }[lineColor]; // 'red'

它交换/切换颜色。红色-->蓝色,蓝色-->红色

lineColor = 'blue';
lineColor = { red: 'red', blue: 'blue' }[lineColor]; // 'red'

它交换/切换颜色。红色-->蓝色,蓝色-->红色

lineColor = 'blue';
lineColor = { red: 'red', blue: 'blue' }[lineColor]; // 'red'

它在
'red'
'blue'
之间切换

假设您从以下内容开始:

lineColor = { red: 'red', blue: 'blue' }.blue; // 'red'
执行此操作将
lineColor
更改为“蓝色”

var lineColor = 'red';
lineColor={red:'blue',blue:'red'}[lineColor];
//该对象的属性[红色]的值为“蓝色”

lineColor/它在
的“红色”和
的“蓝色”之间切换

假设您从以下内容开始:

lineColor = { red: 'red', blue: 'blue' }.blue; // 'red'
执行此操作将
lineColor
更改为“蓝色”

var lineColor = 'red';
lineColor={red:'blue',blue:'red'}[lineColor];
//该对象的属性[红色]的值为“蓝色”

lineColor/它在
的“红色”和
的“蓝色”之间切换

假设您从以下内容开始:

lineColor = { red: 'red', blue: 'blue' }.blue; // 'red'
执行此操作将
lineColor
更改为“蓝色”

var lineColor = 'red';
lineColor={red:'blue',blue:'red'}[lineColor];
//该对象的属性[红色]的值为“蓝色”

lineColor/它在
的“红色”和
的“蓝色”之间切换

假设您从以下内容开始:

lineColor = { red: 'red', blue: 'blue' }.blue; // 'red'
执行此操作将
lineColor
更改为“蓝色”

var lineColor = 'red';
lineColor={red:'blue',blue:'red'}[lineColor];
//该对象的属性[红色]的值为“蓝色”

lineColor/这是一种将切换实现为一行程序的聪明方法。您可以这样打开它:

lineColor = { red: 'blue', blue: 'red' }[lineColor];
// The property [blue] of that object has a value of 'red'

lineColor // <---- 'red'
编辑后注释:可以使用两种以上的颜色创建循环序列:

var lineColor = 'red';
function toggleColor(){
    chart.yAxis[0].update({
        lineColor: lineColor
    });
    var opposites = { red : 'blue', blue : 'red' };
    if( lineColor == 'red' ){
        lineColor = opposites.red; // assigns 'blue' to lineColor
    }
    else if( lineColor == 'blue' ){
        lineColor = opposites.blue; // assigns 'red' to lineColor
    }

    // but you can shorten the above if/else statement to:
    lineColor = opposites[ lineColor ];

    // which can be shortened to this if you don't want to 
    // assign the opposites object to a variable:
    lineColor = { red: 'blue', blue: 'red' }[lineColor];
}

因此,如果当前颜色为红色,则会变为绿色,如果绿色会变为黄色,如果黄色会变为蓝色,如果蓝色会变为红色:

这是一种巧妙的方法,可以将切换实现为一行。您可以这样打开它:

lineColor = { red: 'blue', blue: 'red' }[lineColor];
// The property [blue] of that object has a value of 'red'

lineColor // <---- 'red'
编辑后注释:可以使用两种以上的颜色创建循环序列:

var lineColor = 'red';
function toggleColor(){
    chart.yAxis[0].update({
        lineColor: lineColor
    });
    var opposites = { red : 'blue', blue : 'red' };
    if( lineColor == 'red' ){
        lineColor = opposites.red; // assigns 'blue' to lineColor
    }
    else if( lineColor == 'blue' ){
        lineColor = opposites.blue; // assigns 'red' to lineColor
    }

    // but you can shorten the above if/else statement to:
    lineColor = opposites[ lineColor ];

    // which can be shortened to this if you don't want to 
    // assign the opposites object to a variable:
    lineColor = { red: 'blue', blue: 'red' }[lineColor];
}

因此,如果当前颜色为红色,则会变为绿色,如果绿色会变为黄色,如果黄色会变为蓝色,如果蓝色会变为红色:

这是一种巧妙的方法,可以将切换实现为一行。您可以这样打开它:

lineColor = { red: 'blue', blue: 'red' }[lineColor];
// The property [blue] of that object has a value of 'red'

lineColor // <---- 'red'
编辑后注释:可以使用两种以上的颜色创建循环序列:

var lineColor = 'red';
function toggleColor(){
    chart.yAxis[0].update({
        lineColor: lineColor
    });
    var opposites = { red : 'blue', blue : 'red' };
    if( lineColor == 'red' ){
        lineColor = opposites.red; // assigns 'blue' to lineColor
    }
    else if( lineColor == 'blue' ){
        lineColor = opposites.blue; // assigns 'red' to lineColor
    }

    // but you can shorten the above if/else statement to:
    lineColor = opposites[ lineColor ];

    // which can be shortened to this if you don't want to 
    // assign the opposites object to a variable:
    lineColor = { red: 'blue', blue: 'red' }[lineColor];
}

因此,如果当前颜色为红色,则会变为绿色,如果绿色会变为黄色,如果黄色会变为蓝色,如果蓝色会变为红色:

这是一种巧妙的方法,可以将切换实现为一行。您可以这样打开它:

lineColor = { red: 'blue', blue: 'red' }[lineColor];
// The property [blue] of that object has a value of 'red'

lineColor // <---- 'red'
编辑后注释:可以使用两种以上的颜色创建循环序列:

var lineColor = 'red';
function toggleColor(){
    chart.yAxis[0].update({
        lineColor: lineColor
    });
    var opposites = { red : 'blue', blue : 'red' };
    if( lineColor == 'red' ){
        lineColor = opposites.red; // assigns 'blue' to lineColor
    }
    else if( lineColor == 'blue' ){
        lineColor = opposites.blue; // assigns 'red' to lineColor
    }

    // but you can shorten the above if/else statement to:
    lineColor = opposites[ lineColor ];

    // which can be shortened to this if you don't want to 
    // assign the opposites object to a variable:
    lineColor = { red: 'blue', blue: 'red' }[lineColor];
}



因此,如果当前颜色为红色,则变为绿色,如果绿色变为黄色,如果黄色变为蓝色,如果蓝色变为红色:

什么是
图表
?哪个图书馆提供?不管怎么说,它似乎颠倒了线的颜色…它是通过变量中定义的键访问对象属性,就像
someObject[keyName]
@pawel,但这里有{red:'blue',blue:'red'}[linecolor]它实际上与对象有什么关系?linecolor={red:'red',blue:'blue'}[linecolor];无法理解为什么在lastwhat is
图表中使用此[lineColor]
?哪个图书馆提供?不管怎么说,它似乎颠倒了线的颜色…它是通过变量中定义的键访问对象属性,就像
someObject[keyName]
@pawel,但这里有{red:'blue',blue:'red'}[linecolor]它实际上与对象有什么关系?linecolor={red:'red',blue:'blue'}[linecolor];无法理解为什么在lastwhat is
图表中使用此[lineColor]
?哪个图书馆提供?不管怎么说,它似乎颠倒了线的颜色…它是通过变量中定义的键访问对象属性,就像
someObject[keyName]
@pawel,但这里有{red:'blue',blue:'red'}[linecolor]它实际上与对象有什么关系?linecolor={red:'red',blue:'blue'}[linecolor];无法理解为什么在lastwhat is
图表中使用此[lineColor]
?哪个图书馆提供?不管怎么说,它似乎颠倒了线的颜色…它是通过变量中定义的键访问对象属性,就像
someObject[keyName]
@pawel,但这里有{red:'blue',blue:'red'}[linecolor]它实际上与对象有什么关系?linecolor={red:'red',blue:'blue'}[linecolor];无法理解为什么在lastlineColor={red:'red',blue:'blue'}[lineColor]中使用此[lineColor];无法理解为什么在lastlineColor={red:'red',blue:'blue'}[lineColor]中使用此[lineColor];无法理解为什么在lastlineColor={red:'red',blue:'blue'}[lineColor]中使用此[lineColor];无法理解为什么在lastlineColor={red:'red',blue:'blue'}[lineColor]中使用此[lineColor];无法理解为什么在lastTao中使用此[lineColor],请解释它如何切换…………我无法获取。我可以在obectA中使用两种以上的颜色吗?快速提示是,比如说,您有
var p={red:'blue',blue:'red'}
。取属性
p['blue']
返回“红色”。反之亦然,您使用
p['red']
它会返回“blue”。)好把戏,不是吗?注意:
p.red='blue'
相当于
p['red']='blue'
。您可以通过任何一种方式访问该属性。Tao请解释它如何切换…………我无法获取。我可以在obectA中使用两种以上的颜色吗?快速提示是,比如说,您有
var p={red:'blue',blue:'red'}
。取属性
p['blue']
返回“红色”。反之亦然,您使用
p['red']
它会返回“blue”。)好把戏,不是吗?注意:
p.red='blue'
相当于
p['red']='blue'
。您可以通过任何一种方式访问该属性。Tao请解释它如何切换…………我无法获取。我可以在obectA quick h中使用两种以上的颜色吗