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


Groups > comp.lang.javascript > #30590

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

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: not "autovivification", but ...?
Date 2016-05-31 17:31 +0200
Organization PointedEars Software (PES)
Message-ID <1570701.170j4HGxR2@PointedEars.de> (permalink)
References <autovivification-20160531121607@ram.dialup.fu-berlin.de>

Show all headers | View raw


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.

Back to comp.lang.javascript | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web