I wrote this piece of code and when I call me.trumped.js.calculate(); it tells me that it is not a function //--------define--------// if(!me) var me={}; if(!me.trumped) me.trumped={}; if(!me.trumped.js) me.trumped.js={}; me.trumped.js= function(){ var t = {}; t.a = 1; t.b = 2; t.calculate = function() { t.add = t.a+t.b; document.getElementById('result).value = t.add.toFixed(2); }; return t; }(); Code (markup):
Fixed it and this didn't work. Forgot to mention it doesn't pop up the error, It was shown by firebug
this should work: <input type="text" id="result" /> <script> //--------define--------// if(!me) var me={}; if(!me.trumped) me.trumped={}; if(!me.trumped.js) me.trumped.js={}; me.trumped.js= [B]new[/B] function(){ var t = {}; t.a = 1; t.b = 2; t.calculate = [B]new[/B] function() { t.add = t.a+t.b; document.getElementById('result').value = t.add.toFixed(2); }; return t; } </script> Code (markup):
this should be right: <input type="text" id="result" /> <script> //--------define--------// if(!me) var me={}; if(!me.trumped) me.trumped={}; if(!me.trumped.js) me.trumped.js={}; me.trumped.js= new function(){ var t = {}; t.a = 1; t.b = 2; t.calculate = function() { t.add = t.a+t.b; document.getElementById('result').value = t.add.toFixed(2); }; return t; } me.trumped.js.calculate(); </script> Code (markup):
Cheers mate. This works! Can you explain why "new function()" for me.trumped.js and just "function" for t.calculate?
honestly, no idea. I'm not much good at javascript, but have had to use it a little bit lately with something similar.