accessing objects

7 views
Skip to first unread message

nav indian

unread,
Apr 1, 2012, 7:41:16 AM4/1/12
to prototype-s...@googlegroups.com
Hi 

I have two javascript files.
one.js
namespace("package1")
package1.tabs=function(app)
{
   this.app = app;
   this. createTabs();

createTabs = function(){

  var oneObject = new thirdpartyObject();

}


two.js

//Here I have to access oneObject.





T.J. Crowder

unread,
Apr 2, 2012, 3:58:37 AM4/2/12
to prototype-s...@googlegroups.com
> Here I have to access oneObject.

You can't, it's a local variable within the function you assigned to the `createTabs` variable. Unless you export it (make it publicly accessible in some way, for instance by assigning it to your `package1` object as a property), it's completely private to `createTabs`.

Side note: Your code is falling prey to The Horror of Implicit Globals[1]. Strongly recommend properly declaring variables to avoid that.

--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com
Reply all
Reply to author
Forward
0 new messages