Open gregerolsson opened 13 years ago
Its very likely that the automatic function invokations will get removed, making an explicit call necessary while removing problems like this. The context would then be the object containing the function
Ah, good to know, thanks for the reply.
Yes this relates to the issue on nje/jquery-tmpl: https://github.com/nje/jquery-tmpl/issues/issue/29. I'm keeping this issue open. As Joern says, we expect to make some design changes that will address this in a Beta2 release, probably in April. Keeping this issue open, for tracking.
Thanks for taking the time to submit this issue. Just wanted to let you know this plugin is no longer being actively developed or maintained by the jQuery team. See README for more info.
(sorry for the long question)
I was looking at the plugin code and the docs and I was curious about the reasoning behind the use of
$data
and$item
together with expressions that evaluate to functions. Consider the following template:where the data passed to the template is an object with properties of both function type and primitive types:
If the expression
title
evaluates to a function, the function detector inbuildTmplFn()
will notice that and call the function using$item
asthis
(if it is a "primitive" it will just use its value).This forces either my
title()
function in the "ticket" object to know about the templating system and usethis.data
to get to its "true"this
, or it forces my template to this:I can also put my object in a wrapper and use the wrapper property to access it:
So my actual question is, what is the reason that function expressions are called with
$item
asthis
(which feels leaky) and not with$data
?Thanks!