Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #36905
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Object prop missing? |
| Date | 2019-06-13 17:30 +0200 |
| Organization | PointedEars Software (PES) |
| Message-ID | <4513428.33T0Q7i3B6@PointedEars.de> (permalink) |
| References | (2 earlier) <kcidnW32l-lhgp_AnZ2dnUU7-TvNnZ2d@westnet.com.au> <XnsAA6D7FBCFA34eejj99@194.109.6.166> <4KGdnc1BE6S_tp_AnZ2dnUU7-YXNnZ2d@westnet.com.au> <2720861.OsphAzSTzx@PointedEars.de> <pKGdnVhrbtEIpJ_AnZ2dnUU7-d3NnZ2d@westnet.com.au> |
Andrew Poulos wrote:
> […] but what I can't understand is with this:
>
> console.log(options[1]); // 1.
> console.log(options[1].h); // 2.
>
> why 1. shows a value for h yet 2. (which immediately follows 1.) says h
> is undefined.
Very simple: You have not added the property to the object referred to by
“options[1]”, you have added it and removed it later, or you have set it to
“undefined”. “JJ”’s argument is sound as well.
For example, one can create an object that cannot be augmented with
properties:
var obj = Object.freeze({});
/* TypeError exception only in strict mode */
obj.h = 42;
/* undefined */
console.log(obj.h);
This behavior actually applies to primitive strings since ECMAScript Ed. 5.
[If one wishes to call custom methods on string values, one must augment the
String prototype, or use .call() or .apply() instead.]
--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Object prop missing? Andrew Poulos <ap_prog@hotmail.com> - 2019-06-13 16:25 +1000
Re: Object prop missing? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-06-13 09:37 +0200
Re: Object prop missing? Andrew Poulos <ap_prog@hotmail.com> - 2019-06-13 20:05 +1000
Re: Object prop missing? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-06-13 12:33 +0200
Re: Object prop missing? Andrew Poulos <ap_prog@hotmail.com> - 2019-06-13 20:53 +1000
Re: Object prop missing? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-06-13 13:09 +0200
Re: Object prop missing? Andrew Poulos <ap_prog@hotmail.com> - 2019-06-13 21:54 +1000
Re: Object prop missing? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-06-13 17:30 +0200
Re: Object prop missing? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-06-13 13:05 +0200
Re: Object prop missing? JJ <jj4public@vfemail.net> - 2019-06-13 15:41 +0700
csiph-web