Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #28851
| From | Stefan Weiss <krewecherl@gmail.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Overwriting existing fucntion |
| Date | 2015-10-21 19:47 +0200 |
| Organization | albasani.net |
| Message-ID | <n08j45$cfc$1@news.albasani.net> (permalink) |
| References | <CbCdnUFUDeXC3rnLnZ2dnUU7-amdnZ2d@westnet.com.au> <2283142.7jlluFck8S@PointedEars.de> |
On 2015-10-19 19:49, Thomas 'PointedEars' Lahn wrote: > Different to what Stefan suggested, you should not be using “window” to > refer to the global object, but if you need to make it explicit, “this” in > the global execution context. For example > > /* global context */ > var global = this; This will not give you the global object, but rather the window object again (actually, the window's WindowProxy object) in HTML5: | A global object | | An object that provides the APIs that can be called by the code in | scripts that use this settings object. | | Note: This is typically a Window object or a WorkerGlobalScope | object. When a global object is an empty object, it can't do anything | that interacts with the environment. | | If the global object is a Window object, then, in JavaScript, the | ThisBinding of the global execution context for this script must | be the Window object's WindowProxy object, rather than the global | object. [ECMA262] | | Note: This is a willful violation of the JavaScript specification | current at the time of writing (ECMAScript edition 5, as defined | in section 10.4.1.1 Initial Global Execution Context, step 3). The | JavaScript specification requires that the this keyword in the | global scope return the global object, but this is not compatible | with the security design prevalent in implementations as specified | herein. [ECMA262] http://www.w3.org/TR/html5/webappapis.html#global-object Even before HTML5, I've never heard of a browser in which `window` in the global context would be anything other than a host object giving access to the global object's properties - barring non-document contexts, shadowing, obsolete browsers, and bugs. Unless you're doing something very unusual, the warning to not rely on `window` is unnecessary. - stefan
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Overwriting existing fucntion Andrew Poulos <ap_prog@hotmail.com> - 2015-10-19 12:12 +1100
Re: Overwriting existing fucntion Andrew Poulos <ap_prog@hotmail.com> - 2015-10-19 13:57 +1100
Re: Overwriting existing fucntion Stefan Weiss <krewecherl@gmail.com> - 2015-10-19 05:04 +0200
Re: Overwriting existing fucntion Stefan Weiss <krewecherl@gmail.com> - 2015-10-19 13:14 +0200
Re: Overwriting existing fucntion Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-19 19:49 +0200
Re: Overwriting existing fucntion Andrew Poulos <ap_prog@hotmail.com> - 2015-10-20 10:18 +1100
Re: Overwriting existing fucntion Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-20 02:17 +0200
Re: Overwriting existing fucntion Stefan Weiss <krewecherl@gmail.com> - 2015-10-21 19:47 +0200
Re: Overwriting existing fucntion Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-10-21 21:40 +0200
Re: Overwriting existing fucntion Stefan Weiss <krewecherl@gmail.com> - 2015-10-22 03:04 +0200
Re: Overwriting existing fucntion Danny <dann90038@gmail.com> - 2015-10-19 13:29 -0700
csiph-web