I notice that when using lambdas:
{
"name": "Willy",
"wrapped": function() {
return function(text) {
return "<b>" + render(text) + "</b>"
}
}
}
a second argument (in addition to text) is passed in. This second argument is a function:
function (template) {
return render(template, scope);
}
which returns html, given a template (with the inital input json object).
so, if I were to have the lambda as follows:
"wrapped": function() {
return function(text, func) {
....
}
one would expect func("<div>{{name}}</div>") to return html representing a div with the content being filled in with whatever was in the ‘name’ property of the json data object.
HOWEVER, func("{{.}}") does NOT work.
I would expect the object representing the initial input object.
Instead I get the STRING "[object Object]". When I try to use JSON.parse it gives me an ‘Unexpected token o’ error.
The code you are trying to parse as JSON isn’t actually JSON. It’s just a JavaScript object literal. So when you try to put
{{.}}into your template, you are rightly getting[object Object]because that is the string representation of the object.