Hi,
They're both there to handle property accessors within the template.
It's missing from the documentation, but templates can actually handle
things like:
"Hi #{person[firstname]} #{person.lastname}"
...where what you feed in is:
t.evaluate({person: {
firstname: "Joe",
lastname: "Bloggs"
});
(Example: http://jsbin.com/axuzo3)
The regex plus the loop are what make that happen, both the subscript
notation (the first one) and the dotted notation (the second one). I
think it only works one level deep with the bracketed notation,
though.
HTH,
--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com
On Nov 6, 7:52 pm, petrob <[email protected]> wrote:
> I am learning the Prototype library in-depth and my question is about
> the inner logic of the Template.evaluate method. Everything is clear
> as long as the original match provided by the gsub function from the
> stored template is further processed.
>
> a.) what kind of scenario is the inner regular expresion used to
> handle?
> b.) what is going on in the while loop
>
> /*
> cut
> */
> var pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/;
>
> match = pattern.exec(expr);
> if (match == null) return before;
>
> while (match != null) {
> var comp = match[1].startsWith('[') ? match[2].replace(/\\\\]/
> g, ']') : match[1];
> ctx = ctx[comp];
> if (null == ctx || '' == match[3]) break;
> expr = expr.substring('[' == match[3] ? match[1].length :
> match[0].length);
> match = pattern.exec(expr);
> }
> /*
> cut
> */
--
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en.