Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #30590 > unrolled thread

Re: not "autovivification", but ...?

Started byThomas 'PointedEars' Lahn <PointedEars@web.de>
First post2016-05-31 17:31 +0200
Last post2016-05-31 17:31 +0200
Articles 1 — 1 participant

Back to article view | Back to comp.lang.javascript

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: not "autovivification", but ...? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-05-31 17:31 +0200

#30590 — Re: not "autovivification", but ...?

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2016-05-31 17:31 +0200
SubjectRe: not "autovivification", but ...?
Message-ID<1570701.170j4HGxR2@PointedEars.de>
Stefan Ram wrote:

> […] we do have
> 
> "use strict"; this.b = 1;
> 
>   . That is, when »this.b« is a assigned to - even in strict mode -
>   a new property »b« is implicitly created. No declaration (with
>   »var«, »let«, or »const«) is required.
> 
>   Is there a name for this »feature« of JavaScript?

Property write access.  It does not only work with the object referred to by 
“this” – which, you should keep in mind, does not have to be so particularly 
in strict mode – but with all objects that have the [[Extensible]] flag set.

Also, you want to be careful here: assigning to a property of “this” can 
result in the creation of the equivalent of a global variable when a 
function in which it is used is not called as a constructor, and it results 
in a ReferenceError exception thrown in function context in strict mode if 
the function is neither called as the method of an object nor as a 
constructor.

“Autovivification” (in C#: null propagation) would certainly be useful at 
times (very often you just want to get “undefined” from x.y.z when x.y 
yields “undefined” instead of typeof-testing the whole shebang, and
x.y.z = 1 when x.y is “undefined”; consider arrays of objects), and is 
available in CoffeeScript as the “accessor variant of the existential 
operator“:

  x?.y.z

<http://stackoverflow.com/questions/15260732/does-typescript-support-the-operator-and-whats-it-called>

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

[toc] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web