473,795 Members | 2,967 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Accessing the global object

Bob
Is there anyway to access the global object from inside a function other
than doing a "var _global = this;" before declaring the function?

Thanks
Feb 22 '08 #1
15 2057
"Bob" <no****@nowhere .comwrites:
Is there anyway to access the global object from inside a function other
than doing a "var _global = this;" before declaring the function?
If you know the name of the global and you're sure you're not overriding
the name, you can use the global name.

IWO, yes and no.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Feb 22 '08 #2
On Feb 21, 5:10 pm, "Bob" <nob...@nowhere .comwrote:
Is there anyway to access the global object from inside a function other
than doing a "var _global = this;" before declaring the function?
In a web browser the global object is usually available as a property
"window" of the global object. I think your idea of creating your own
"_global" is better. In ECMAScript 4 there will be a default "global"
property of the global object that references the global object. It
will work like "window" but "window" is a bad name when scripting in a
non-browser host.

Peter
Feb 22 '08 #3
Bob wrote:
Is there anyway to access the global object from inside a
function other than doing a "var _global = this;" before
declaring the function?
In javascript the value of the - this - keyword is determined by how a
function is called. If the function is not called as a method of an object
the value of the - this - keyword defaults to a reference to the global
object. As a result, from any context you can get a reference to the global
object using:-

function x(){
...
var localGlobalRef = function(){retu rn this;}();
...
}

This is 100% reliable in ECMAScript 3rd Ed. implementations , and quite
useful, but it looks like ES 4 will not be back-compatible with ES 3 in this
regard. Still, not being back-compatible with ES 3 may (fingers crossed) be
enough to kill ES 4 in its cradle so maybe that is not worth worrying about.

Richard.
Feb 22 '08 #4
Bob
Interesting. Is there anyway to distinguish ES3 from ES4, and if ES4 is
present then return the global property?

Thanks very much
"Richard Cornford" <Ri*****@litote s.demon.co.ukwr ote in message
news:fp******** ***********@new s.demon.co.uk.. .
Bob wrote:
>Is there anyway to access the global object from inside a
function other than doing a "var _global = this;" before
declaring the function?

In javascript the value of the - this - keyword is determined by how a
function is called. If the function is not called as a method of an object
the value of the - this - keyword defaults to a reference to the global
object. As a result, from any context you can get a reference to the
global
object using:-

function x(){
...
var localGlobalRef = function(){retu rn this;}();
...
}

This is 100% reliable in ECMAScript 3rd Ed. implementations , and quite
useful, but it looks like ES 4 will not be back-compatible with ES 3 in
this
regard. Still, not being back-compatible with ES 3 may (fingers crossed)
be
enough to kill ES 4 in its cradle so maybe that is not worth worrying
about.

Richard.


Feb 22 '08 #5
AKS
On Feb 22, 2:54 pm, "Richard Cornford" <Rich...@litote s.demon.co.uk>
wrote:
but it looks like ES 4 will not be back-compatible with ES 3 in this
regard. Still, not being back-compatible with ES 3 may (fingers crossed) be
enough to kill ES 4 in its cradle so maybe that is not worth worrying about.
Will be this compatible with ES4?

var localGlobalRef = (function () { return this; }).call(null);

Feb 22 '08 #6
Peter Michaux wrote:
On Feb 21, 5:10 pm, "Bob" <nob...@nowhere .comwrote:
>Is there anyway to access the global object from inside a function
other than doing a "var _global = this;" before declaring the function?

In a web browser the global object is usually available as a property
"window" of the global object.
Nonsense. You are jumping to conclusions.
I think your idea of creating your own "_global" is better.
See <47************ **@PointedEars. de>, among others.
In ECMAScript 4 there will be a default "global" property of the global
object that references the global object.
I am looking forward to that.
It will work like "window" but "window" is a bad name when scripting in a
non-browser host.
However, how is the issue of accessing properties of the Global Object of
another global execution context going to to be addressed, as with frames
and windows?
PointedEars
--
var bugRiddenCrashP ronePieceOfJunk = (
navigator.userA gent.indexOf('M SIE 5') != -1
&& navigator.userA gent.indexOf('M ac') != -1
) // Plone, register_functi on.js:16
Feb 24 '08 #7
On Feb 23, 5:37 pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
Peter Michaux wrote:
On Feb 21, 5:10 pm, "Bob" <nob...@nowhere .comwrote:
Is there anyway to access the global object from inside a function
other than doing a "var _global = this;" before declaring the function?
In a web browser the global object is usually available as a property
"window" of the global object.

Nonsense. You are jumping to conclusions.
The word "usually" usually indicates one is not making a definitive
conclusion.

I think your idea of creating your own "_global" is better.

See <47C0C97C.5010. ..@PointedEars. de>, among others.
In ECMAScript 4 there will be a default "global" property of the global
object that references the global object.

I am looking forward to that.
It will work like "window" but "window" is a bad name when scripting in a
non-browser host.

However, how is the issue of accessing properties of the Global Object of
another global execution context going to to be addressed, as with frames
and windows?
this.opener

this.parent

this.frames

Peter
Feb 24 '08 #8
On Feb 24, 3:20 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
Peter Michaux wrote:
[...] Thomas 'PointedEars' Lahn [...] wrote:
Peter Michaux wrote:
On Feb 21, 5:10 pm, "Bob" <nob...@nowhere .comwrote:
Is there anyway to access the global object from inside a function
other than doing a "var _global = this;" before declaring the function?
In a web browser the global object is usually available as a property
"window" of the global object.
Nonsense. You are jumping to conclusions.
The word "usually" usually indicates one is not making a definitive
conclusion.

The word "usually" implies a perceived majority of cases where said
condition would apply.
Then I said what I meant. The overwhelming majority of JavaScript
hosts on earth are web browsers that have the global "window"
property.

>In ECMAScript 4 there will be a default "global" property of the global
object that references the global object.
I am looking forward to that.
>It will work like "window" but "window" is a bad name when scripting in a
non-browser host.
However, how is the issue of accessing properties of the Global Object of
another global execution context going to to be addressed, as with frames
and windows?
this.opener
this.parent
this.frames

That would imply ECMAScript Edition 4 is going to standardize properties of
Window host objects as built-in properties of the Global Object
I don't see a problem. As far as I know, they aren't standardizing the
properties of the global object, they are simply standardizing a way
to access the global object that can be sensibly used in a non-browser
host.

[snip <--- look Thomas, I snipped]

By the way, http://pointedears.de/scripts/ is still an error page.

Peter
Feb 24 '08 #9
On Feb 24, 10:36 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
wrote:
Peter Michaux wrote:
[...] Thomas 'PointedEars' Lahn [...] wrote:
Peter Michaux wrote:
[...] Thomas 'PointedEars' Lahn [...] wrote:
Peter Michaux wrote:
On Feb 21, 5:10 pm, "Bob" <nob...@nowhere .comwrote:
Is there anyway to access the global object from inside a function
other than doing a "var _global = this;" before declaring the function?
In a web browser the global object is usually available as a property
"window" of the global object.
Nonsense. You are jumping to conclusions.
The word "usually" usually indicates one is not making a definitive
conclusion.
The word "usually" implies a perceived majority of cases where said
condition would apply.
Then I said what I meant. The overwhelming majority of JavaScript
hosts on earth are web browsers that have the global "window"
property.

Then I'm afraid your argument is a fallacious one indeed.
You've said things like this many times. As far as I know you have not
ever listed where these other billions of user agents are that are
not web browsers similar to IE4+/NN4+. Who/What/Where/Why/When/How are
they?

Peter
Feb 24 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2109
by: Fernando Rodríguez | last post by:
Hi, I haven't used Python in quite some time, and I'm bit puzzled by this: counter = 0 class Blah(object): def run(self): counter += 1
2
2395
by: C Gillespie | last post by:
Dear All, I have 2 arrays var A1 = new Array(); A1 ="Y2"; var B1 = new Array(); B1 ="Y1"; B1 ="sink";
2
2626
by: Ekul | last post by:
I have an application that allows users to login and logout. I track how many users are logged in and when each individual is logged in. The application will not allow concurrent logins(let a user log in twice at the same time). My problem is I am having trouble telling when the user is logged off. If they click the logout button everything works fine. But if the close the browser by clicking the x or navigate to another url through the...
0
12089
by: sonu | last post by:
I have following client side code which i have used in my asp.net project SummaryFeatured Resources from the IBM Business Values Solution Center WHITEPAPER : CRM Done Right Improve the likelihood of CRM success from less than 20 percent to 60 percent. WHITEPAPER :
10
1640
by: Christian Christmann | last post by:
Hi, I'm wondering if my small example is not "dangerous": #define SIZE 10 char global; char* globalPtr = global; int main()
12
11724
by: Steve Blinkhorn | last post by:
Does anyone know of a way of accessing and modifying variables declared static within a function from outside that function? Please no homilies on why it's bad practice: the context is very particular and involves automatically generated code. I know several other ways of attacking my problem, but this would be the cleanest if it could be made to work. A little more context. I use C as the output of a code generating system which...
2
1898
by: rgparkins | last post by:
Hi Guys Maybe a simple and easy solution to this, but I keep getting exception object not set to instance etc etc. I have a Timer that is initiated in Application_Start in Global.asax. This timer I am using as a service every 10 minutes to send email to users. OK so all is fine until I need to load a file from the server (in fact an email template).
10
2368
by: Nemisis | last post by:
Hi everyone, I am trying to create a custom error page, that the user gets shown when a error has occurred within my website. The code works perfectly, apart from when an invalid URL is typed in, then i am unable to pass the exception from the global.asax file to the page via the sessionstate. Everytime i try to pass something into the sessionstate i get a error message of 'Object reference not set to an instance of an object.'
3
1785
by: anoop.kn | last post by:
Is there anyway to access Global Function Pointer from its name ? I want to call the function at runtime during a script execution. PS: eval() works, I looking for a more efficient way of doing the same ! Ex: function testfunction ( msg ) { alert( msg );
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10213
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9040
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.