XML Feeds

.

[javascript-dev] Re: @-style attributes in js...

sean ahern sxa at whiterabbitdesign.co.uk
Sun May 4 04:59:43 MDT 2008


In 4.6, I just parse them using some prewritten code.  

Basically, I create the variable and default value, and add its name to an array of valid attribute names.  Then I parse jsarguments for properly-formed pairs which match the format @ATTR1 VALUE (checking for the presence of ATTR1  in the atribute array).  Finally I use an eval to set the value of a variable corresponding to the attribute name (ATTR=VALUE).
My parser also handles position-dependent arguments.
Apart from the code used to do the parsing etc (which isnt particularly optimised, so about 60 lines long), which could be included in a code template, that reduces my argument and attribute parsing to the following:

args = new argHandler;
// note - declare arguments in order;
var ARG1 = 100;
args.setUpArgument("ARG1");
var ARG2 = 0;
args.setUpArgument("ARG2");
var ATTR1 = 100;
args.setUpAttribute("ATTR1");
args.argumentParser(jsarguments);
// required : reads and evals supplied arguments
args.reportAttributes();
// posts all attributes as per a non-js patcher




More information about the javascript-dev mailing list