[英]Hex colours in Javascript
在javaScript中(在Photoshop中),当给十六进制颜色赋值时,它用引号引起来,例如“ FCAA00”
var hexCol = "FCAA00";
var fgColor = new SolidColor;
fgColor.rgb.hexValue = hexCol
但是当将变量传递给该值时,您不需要引号。 为什么是这样?
var hexCol = convertRgbToHex(252, 170, 0)
hexCol = "\"" + hexCol + "\""; // These quotes are not needed.
var fgColor = new SolidColor;
fgColor.rgb.hexValue = hexCol
这仅仅是一个JavaScript怪癖,还是我错过了幕后发生的事情? 谢谢。
引号是一种语法构造,表示字符串文字 。 即,解析器知道引号之间的字符形成字符串的值。 这也意味着它们不是值本身的一部分,它们仅与解析器相关。
例子:
// string literal with value foo
"foo"
// the string **value** is assigned to the variable bar,
// i.e. the variables references a string with value foo
var bar = "foo";
// Here we have three strings:
// Two string literals with the value " (a quotation mark)
// One variable with the value foo
// The three string values are concatenated together and result in "foo",
// which is a different value than foo
var baz = "\"" + bar + "\"";
最后一种情况是您尝试过的。 它创建一个字面包含引号的字符串。 相当于写作
"\"foo\""
这明显不同于"foo"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.