I have what is I believe an extremely basic javascript question that for some silly reason I am struggling with.
If you visualise the object below. How would I call one function from inside the ‘init’ function?
TC.design = {
init : function(){
//How would I run the loadPage function here?
},
loadPage : function(){
}
}
I have tried this.loadPage(); which I expected to work but it returns undefined.
I am clearly not grasping something fundamental here, hopefully someone can explain.
EDIT: This is now solved…
Thanks to Joseph Silber and Rocket I have realised my error…
The problem arose due to a misunderstanding of the javascript .call() function. I was calling init with TC.design.init.call() which I now understand is incorrect. My apologies….
Within your
initfunction,thisrefers to theTG.designobject;this.loadPage()should work, but you have to call theinitfunction properly in order to invoke it.Here’s some sample code:
and here’s the fiddle: http://jsfiddle.net/85AWT/