在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怪癖,还是我错过了幕后发生的事情,就像它一样。谢谢。
答案 0 :(得分:3)
引号是一个句法结构,表示字符串文字。即解析器知道引号之间的字符形成字符串的值。这也意味着它们不是值本身的一部分,它们仅与解析器相关。
示例:
// 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"
。