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


Groups > comp.lang.javascript > #27968

Re: Differences between [[Class]] and constructor

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: Differences between [[Class]] and constructor
Date 2015-06-02 23:05 +0200
Organization PointedEars Software (PES)
Message-ID <1568741.VfgIOpCQGZ@PointedEars.de> (permalink)
References <ct69cmFtvojU1@mid.uni-berlin.de> <mkl0d3$c6d$1@news.albasani.net>

Show all headers | 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


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