Syntax error in StackSupport.jsx
Posted: Thu Dec 11, 2008 3:21 pm
I've been trying to incorporate some Photoshop javascript functions (in particular Photomerge.jsx) for use in my own code, but when I copied this code segment from StackSupport.jsx, I discovered it contains a severe syntax error that bombs on execution, and yet this code apparently works in the Photoshop Photomerge function!
How can Photomerge be working properly in Photoshop when this part of the code does not?
Code: Select all// Convert plain string to the alignment key.
// Avoids clients having to load Terminology.jsx
//
// ((Copied from Adobe Photoshop CS4\Presets\Scripts\Stack Scripts Only\StackSupport.jsx
// lines 577-589. Steve Lehar 12/10/08))
//
function stringToAlignmentKey( alignMethod )
{
// Today's JavaScript lesson: You can not use the constants above in the table below, because
// the parser interns the symbol on the left of the ":" into a new ID, whether or not it's already
// defined in scope. The new interned symbols only work as object field IDs (table.xyz) not
// array indicies (table[xyz])
// ((Steve Lehar's comment: ))
// The following line, (now //commented out) found in the original Photoshop code, BOMBS on execution!
// var table = {"interactive":kinteractiveStr, "Prsp":keyPerspectiveIndex, "Auto":keyAuto, "spherical":ksphericalStr, "cylindrical":kcylindricalStr, "translation":ktranslationStr, "sceneCollage":ksceneCollageStr};
// ((Steve Lehar's comment: ))
// The same line, syntax corrected, runs OK without bombing. What gives?
var table = {interactive:"kinteractiveStr", Prsp:"keyPerspectiveIndex", Auto:"keyAuto", spherical:"ksphericalStr", cylindrical:"kcylindricalStr", translation:"ktranslationStr", sceneCollage:"ksceneCollageStr"};
if (typeof(alignMethod) == "string")
alignMethod = table[alignMethod];
return alignMethod;
}
How can Photomerge be working properly in Photoshop when this part of the code does not?
Code: Select all// Convert plain string to the alignment key.
// Avoids clients having to load Terminology.jsx
//
// ((Copied from Adobe Photoshop CS4\Presets\Scripts\Stack Scripts Only\StackSupport.jsx
// lines 577-589. Steve Lehar 12/10/08))
//
function stringToAlignmentKey( alignMethod )
{
// Today's JavaScript lesson: You can not use the constants above in the table below, because
// the parser interns the symbol on the left of the ":" into a new ID, whether or not it's already
// defined in scope. The new interned symbols only work as object field IDs (table.xyz) not
// array indicies (table[xyz])
// ((Steve Lehar's comment: ))
// The following line, (now //commented out) found in the original Photoshop code, BOMBS on execution!
// var table = {"interactive":kinteractiveStr, "Prsp":keyPerspectiveIndex, "Auto":keyAuto, "spherical":ksphericalStr, "cylindrical":kcylindricalStr, "translation":ktranslationStr, "sceneCollage":ksceneCollageStr};
// ((Steve Lehar's comment: ))
// The same line, syntax corrected, runs OK without bombing. What gives?
var table = {interactive:"kinteractiveStr", Prsp:"keyPerspectiveIndex", Auto:"keyAuto", spherical:"ksphericalStr", cylindrical:"kcylindricalStr", translation:"ktranslationStr", sceneCollage:"ksceneCollageStr"};
if (typeof(alignMethod) == "string")
alignMethod = table[alignMethod];
return alignMethod;
}