Loading...

prototype-scriptaculous@googlegroups.com

[Prev] Thread [Next]  |  [Prev] Date [Next]

Re: [Proto-Scripty] Re: accessing global objects T.J. Crowder Mon Apr 02 07:01:29 2012

>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

On Monday, 2 April 2012 12:21:44 UTC+1, nav indian wrote:
>
>        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 <[EMAIL PROTECTED]>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.
>>
>> 1: http://blog.niftysnippets.org/2008/03/horror-of-implicit-globals.html
>>
>> Best,
>> --
>> 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 
>> [EMAIL PROTECTED]
>> To unsubscribe from this group, send email to 
>> [EMAIL PROTECTED]
>> For more options, visit this group at 
>> http://groups.google.com/group/prototype-scriptaculous?hl=en.
>>
>
>

-- 
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/-/hJoyflIZoi8J.
To post to this group, send email to [EMAIL PROTECTED]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.