Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #14587
| Message-ID | <1615243.oMNUckLgyt@PointedEars.de> (permalink) |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Organization | PointedEars Software (PES) |
| Date | 2012-06-20 15:43 +0200 |
| Subject | Re: Function Objects |
| Newsgroups | comp.lang.javascript |
| References | <bm22u7l5dbs0rrdeloru3fd3sct7n8g201@4ax.com> <jrr4cc$k5u$1@news.albasani.net> |
| Followup-To | comp.lang.javascript |
Followups directed to: comp.lang.javascript
Stefan Weiss wrote:
> The effect may be easier to understand if you use a simpler
> self-contained example without host objects:
>
> var dog = {
> noise: "wow!",
> bark: function () { alert(this.noise); }
> };
>
> dog.bark(); // "wow!"
>
> var alias = dog.bark;
>
> alias(); // "undefined"
>
> The last line yields "undefined" because |this| in the function body now
> refers to the global object, which has no "noise" property.
Evaluation of `this.noise' throws a TypeError exception in strict mode when
alias() is called, because `this' would be `undefined' then, and `undefined'
by definition has no properties.
The strict mode of ECMAScript (introduced in Edition 5 [1]) is particularly
useful if you want to avoid accessing the global object, but it is neither
correctly implemented in otherwise conforming implementations yet nor
available in all implementations at all. However, if you `"use strict";'
mode, and test your code with a sufficiently conforming implementation (like
Google V8 3.7.12.12 in Chrome 17.0.963.78¹), a lot of common programming
mistakes can be avoided.
PointedEars
___________
¹ This feature and tests thereof are contained in the next version of the
ECMAScript Support Matrix that I am preparing.
[1] <http://ecma-international.org/ecma-262/5.1/#sec-C>
--
When all you know is jQuery, every problem looks $(olvable).
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Function Objects Gene Wirchenko <genew@ocis.net> - 2012-06-19 16:35 -0700
Re: Function Objects Stefan Weiss <krewecherl@gmail.com> - 2012-06-20 02:09 +0200
Re: Function Objects Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-06-20 15:43 +0200
Re: Function Objects Stefan Weiss <krewecherl@gmail.com> - 2012-06-20 17:29 +0200
csiph-web