Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 22 by nadir.seen.fire: JavaScript JSONTemplate cannot be  
prototyped
http://code.google.com/p/json-template/issues/detail?id=22

The Template class in JSONTemplate cannot be prototyped.
ie: You cannot add a function to jsontemplate.Template.prototype and make
use of it.

I tried making use of json-template inside of a Server Side environment and
wanted to prototype in a function to save a rendered template to the disk.
Because of the way Template returns a new object rather than acting like a
proper JavaScript class.

Rather than returning a new object Template should do something like this
at the very least:
{{{
function Template(template_str, options) {
   if(!( this instanceof Template )) return new Template(template_str,  
options);
   // options.undefined_str can either be a string or undefined
   options = options || {};

   var program = _Compile(template_str, options);

   this.render = function(data_dict, callback) {
     var context = _ScopedContext(data_dict, options.undefined_str);
     _Execute(program.Statements(), context, callback);
   };

   this.expand = function(data_dict) {
     var tokens = [];
     this.render(data_dict, function(x) { tokens.push(x); });
     return tokens.join('');
   };
};
}}}

Though the proper thing to do would be to make at least expand part of
Template's prototype. Even better if render is part of it and the
constructor is reduced to adding something like `this._program =
_Compile(template_str, options);`.

--
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to