這是在the obfuscator you're using的錯誤。您的代碼
var pgetColor = {
'AB': '#CAD17D',
'BC': '#7DD1AE',
'CL': '#919AFF',
'CI': '#FFE291',
'HB': '#84DBD5',
'ON': '#AA84DB',
'PM': '#DB848A',
'SR': '#B5DB84',
'TS': '#C96B9B',
'IS': '#FFC926',
'FREE': '#5FCF68'
};
是越來越變成這樣(我添加了一個換行符):
var _0x5523=["\x41\x42","\x23\x43\x41\x44\x31\x37\x44","\x42\x43","\x23\x37\x44\x44\x31\x41\x45","\x43\x4C","\x23\x39\x31\x39\x41\x46\x46","\x43\x49","\x23\x46\x46\x45\x32\x39\x31","\x48\x42","\x23\x38\x34\x44\x42\x44\x35","\x4F\x4E","\x23\x41\x41\x38\x34\x44\x42","\x50\x4D","\x23\x44\x42\x38\x34\x38\x41","\x53\x52","\x23\x42\x35\x44\x42\x38\x34","\x54\x53","\x23\x43\x39\x36\x42\x39\x42","\x49\x53","\x23\x46\x46\x43\x39\x32\x36","\x46\x52\x45\x45","\x23\x35\x46\x43\x46\x36\x38"];
var pgetColor={_0x5523[0]:_0x5523[1],_0x5523[2]:_0x5523[3],_0x5523[4]:_0x5523[5],_0x5523[6]:_0x5523[7],_0x5523[8]:_0x5523[9],_0x5523[10]:_0x5523[11],_0x5523[12]:_0x5523[13],_0x5523[14]:_0x5523[15],_0x5523[16]:_0x5523[17],_0x5523[18]:_0x5523[19],_0x5523[20]:_0x5523[21]};
// ------------^^^^^^^^^^
// This is wrong (as are the ones that follow)
這是無效的有_0x5523[0]
在對象初始化屬性名稱。你似乎使用上的:
—它被過分熱心的字符串替換的左側字符串文字,而不是屬性名文字搞糊塗了。 (如果你不太明白「string literal」和「property name literal」的含義,請看下面的內容。)因爲你所做的事情是完全正確和合理的,所以這是混淆器中的一個錯誤。
我會用不同的混淆,或更好,但像Closure compiler的編譯器。
如果我更改代碼使用屬性名稱,而不是文字:
var pgetColor = {
AB: '#CAD17D',
BC: '#7DD1AE',
CL: '#919AFF',
CI: '#FFE291',
HB: '#84DBD5',
ON: '#AA84DB',
PM: '#DB848A',
SR: '#B5DB84',
TS: '#C96B9B',
IS: '#FFC926',
FREE: '#5FCF68'
};
...結果是罰款:
var _0x8d33=["\x23\x43\x41\x44\x31\x37\x44","\x23\x37\x44\x44\x31\x41\x45","\x23\x39\x31\x39\x41\x46\x46","\x23\x46\x46\x45\x32\x39\x31","\x23\x38\x34\x44\x42\x44\x35","\x23\x41\x41\x38\x34\x44\x42","\x23\x44\x42\x38\x34\x38\x41","\x23\x42\x35\x44\x42\x38\x34","\x23\x43\x39\x36\x42\x39\x42","\x23\x46\x46\x43\x39\x32\x36","\x23\x35\x46\x43\x46\x36\x38"];
var pgetColor={AB:_0x8d33[0],BC:_0x8d33[1],CL:_0x8d33[2],CI:_0x8d33[3],HB:_0x8d33[4],ON:_0x8d33[5],PM:_0x8d33[6],SR:_0x8d33[7],TS:_0x8d33[8],IS:_0x8d33[9],FREE:_0x8d33[10]};
但有時當你真的想向使用屬性名稱的字符串文字(例如,如果屬性名稱中有空格或保留字)。
美化的混淆代碼,然後用jsHint測試它,看它是否是混淆代碼這是錯誤的(這意味着混淆實現是錯誤的)。只是一個提示:混淆並沒有幫助。它只是增加了處理。 Minifying/uglifying會更好。 – Joseph 2013-05-14 14:40:03
你用什麼工具來混淆代碼? – 2013-05-14 14:40:59
是的,這是一個語法錯誤,你不能擁有那個'['那裏。我會使用一個不同的混淆器。 – 2013-05-14 14:41:36