i am rendering a jade file as :
On server side :
var html = jade.renderFile('ui/index.jade', {
printHello : function(){
console.log('Hello World');
}
});
On client side in index.jade
:
script(type="text/javascript").
var s = #{JSON.stringify(patternMatch)};
s.printHello(); //Desired to print 'Hello world' on browser console
But s.printHello()
says Object Object does not have function 'printHello';
and console.log(s);
// gives {} 'empty object';
Why is that so.?
And how do i make printHello
present and work?
this is what i did. i send the stringed code from server
var html = jade.renderFile('ui/index.jade', {
printHello : "("+"function(){ console.log('Hello World'); }"+")"
});
Then on client side
script(type="text/javascript").
var s = !{JSON.stringify(patternMatch)};
var myFunc = eval(s['printHello'])
console.log(myFunc()); //prints "Hello World" on client browser