Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27968
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail |
|---|---|
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
| Newsgroups | comp.lang.javascript |
| Subject | Re: Differences between [[Class]] and constructor |
| Date | Tue, 02 Jun 2015 23:05:48 +0200 |
| Organization | PointedEars Software (PES) |
| Lines | 47 |
| Message-ID | <1568741.VfgIOpCQGZ@PointedEars.de> (permalink) |
| References | <ct69cmFtvojU1@mid.uni-berlin.de> <mkl0d3$c6d$1@news.albasani.net> |
| Reply-To | Thomas 'PointedEars' Lahn <cljs@PointedEars.de> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset="UTF-8" |
| Content-Transfer-Encoding | 8Bit |
| X-Trace | solani.org 1433279312 31266 eJwFwYEBwCAIA7CXQCjVczqR/09YgiivyyxUYjDk0NZ7l07VQuRXbdsUfpqyJfUemQfIM/0DEN0QzA== (2 Jun 2015 21:08:32 GMT) |
| X-Complaints-To | abuse@news.solani.org |
| NNTP-Posting-Date | Tue, 2 Jun 2015 21:08:32 +0000 (UTC) |
| User-Agent | KNode/4.14.2 |
| X-User-ID | eJwFwQERADEIAzBL9KCFyRl78C/hE7qglyEquNw7YFl+hXAcEL7zTo8PTnbUa9FspJCqq+NmW7FnEd+gfjoOFQs= |
| Cancel-Lock | sha1:veY00XSecUtrF+rFfFTctdAlnnM= |
| X-NNTP-Posting-Host | eJwFwYERAEEEBLCWeCxfjln0X8IlYVAwHQGPi/utQoyzuC6FTEokrXVrPz/y2Ls+TT/vxQMhjhIg |
| Xref | csiph.com comp.lang.javascript:27968 |
Show key headers only | View raw
Andreas Bergmaier wrote:
> Stefan Ram schrieb:
>> I have observed that the class ([[Class]]) name and the
>> constructor name of an object often is the same!
>
> This might be the case for plain objects with the native constructors.
> It is not for almost every other object, like
>
> var p = new (function Person(){});
> className(p) // "object"
No, with this code it would be a capital “O”.
> p.constructor // Person
>
>> The first difference I found is: You can change the
>> constructor name, but not the class name.
>
> Not exactly. You cannot change constructor names either, as the `.name`
> property of functions is typically non-writable (if it exists at all, it
> is non-standard, as opposed to [[Class]]). See
> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
> for more information.
>
> What you can arbitrarily change is the `.constructor` property of any
> normal object, there are no limitiations here.
Whereas “normal object” would be one whose prototype is not constructed
using (an emulation of) Object.create(…), as I pointed out in an update of
my <http://stackoverflow.com/a/12593269/855543> today:
With a conforming implementation of Object.create(), following
WeatherWidget.prototype =
Object.create(Widget.prototype, {constructor: {value: WeatherWidget}});
the “constructor” property of WeatherWidget instances is neither writable,
nor enumerable or configurable. Of those, an emulation of Object.create()
can only accomplish read-onlyness, see Function.prototype.extend() in
JSX:object.js.
--
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 — Previous in thread | Find similar | Unroll thread
Re: Differences between [[Class]] and constructor Andreas Bergmaier <andber93@web.de> - 2015-06-02 21:32 +0200 Re: Differences between [[Class]] and constructor Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-02 23:05 +0200
csiph-web