Comment #2 on issue 22 by nadir.seen.fire: JavaScript JSONTemplate cannot
be prototyped
http://code.google.com/p/json-template/issues/detail?id=22
Ok, sorry, I haven't had time to tweak the json-template code till now.
This patch should fix the issue.
My preference is to make expand and render part of the prototype and set
variables
like this._options and this._program so that they can use it. Using a
closure is
still an option if you're really desperate for it.
The difference is extreme privacy vs. wasted memory.
The closure does hide the program variable and options from being modified
from the
outside. But I don't see to much purpose for that, there are thousands of
other ways
you could break anything in JavaScript, the _ prefix is enough to
say "Don't touch
this, if you do, whatever breaks is your fault."
The problem of course with the closure is that for each template completely
new
functions are created. This wastes memory on extra functions when they
could just be
common functions to all Template instances. It also means that you can't
use the
proxy-method pattern to enhance the abilities of the existing methods. And
if you
don't set this._options then any methods users prototype onto the Template
don't have
the ability to look at the options used to create the template and act
properly based
on them.
Attachments:
prototype.patch 1.4 KB
--
You received this message because you are listed in the owner
or CC fields of this issue, or because you starred this issue.
You may adjust your issue notification preferences at:
http://code.google.com/hosting/settings
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "JSON
Template" 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/json-template?hl=en
-~----------~----~----~----~------~----~------~--~---