Re: [Proto-Scripty] Re: accessing global objects

9 views
Skip to first unread message

Navindian

unread,
Apr 2, 2012, 7:21:44 AM4/2/12
to prototype-s...@googlegroups.com
       even after declaring as global, it is still not accessible . the following code will get an idea.
one.js
namespace("package1")
       var oneObject ;
package1.tabs=function(app)
{
   this.app = app;
   this. createTabs();

createTabs = function(){

  oneObject = new thirdpartyObject();

}


two.js

//Here I have to access oneObject.


On Mon, Apr 2, 2012 at 1:28 PM, T.J. Crowder <t...@crowdersoftware.com> wrote:
> 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

On Sunday, 1 April 2012 12:41:16 UTC+1, nav indian wrote:
Hi 

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

createTabs = function(){

  oneObject = new thirdpartyObject();

}


two.js

//Here I have to access oneObject.





--
You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group.
To view this discussion on the web visit https://groups.google.com/d/msg/prototype-scriptaculous/-/XJ20PmyWnIQJ.

To post to this group, send email to prototype-s...@googlegroups.com.
To unsubscribe from this group, send email to prototype-scripta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.

T.J. Crowder

unread,
Apr 2, 2012, 9:16:12 AM4/2/12
to prototype-s...@googlegroups.com
From the code you've quoted, it would be accessible, there must be more to it than that. Can you provide a minimalist test case on http://jsbin.com or similar?

--
T.J. Crowder
Independent Software Engineer
tj / crowder software / com
www / crowder software / com


To post to this group, send email to prototype-scriptaculous@googlegroups.com.
To unsubscribe from this group, send email to prototype-scriptaculous+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages