By analyzing the peaces of codes below I had come to a conclusion that few things aren’t clear to me which need clarification. They are excerpt from an Adobe’s PS script.
At the first code sample, statements inside the function append are separated by comma instead by semicolon, but, if you notice, only if they are in one line. If a statement begins on a new line, there is no comma separation.
Does this mean that the usage of comma instead of semicolon inside function is completely valid and no statement separator at all if placed on a new line?
stID = stringIDToTypeID; function append(par1, par2) {
aR = new ActionReference(), aD = new ActionDescriptor()
aR.putProperty(stID('property'), stID(par2 || 'pattern')), aR.putClass(stID 'application'))
aD.putReference(stID('null'), aR), aD.putPath(stID('to'), File(dpt + ht + 'someFolder/' + par1))
aD.putBoolean(stID('append'), true), executeAction(stID('set'), aD, DialogModes.NO)
}
At the second code sample the function expression is wrapped in parentheses followed by a JS property. Is this an IIFE or something else that I don’t know of?
(w = wh('grp1', 'Width')).active = true
At the third code sample, simply what are the + symbols placed in front of the w object?
That is a confusing comma operator being used. All statements get executed, but if an assignment is on the left then only the last statement gets assigned.
var a = b(), c(), d(); // all are executed, and a equals the result from d()
I don’t think that there’s any benefit of coding in that type of style;
[quote=“xede1, post:1, topic:351323, full:true”]
At the second code sample the function expression is wrapped in parentheses followed by a JS property. Is this an IIFE or something else that I don’t know of?
(w = wh('grp1', 'Width')).active = true
I don’t even want to try and understand what the hell that’s doing. That’s a very good example of bad and confusing code.
That is a shorthand way to convert a string into a number. It’s usually advised against, because it just ends up being confusing.
Why are all of those confusing things being done? Mostly it’s because programmers are showing off about saving a few characters. That comes at the cost of being able to easily understand what it’s doing.