Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #27963 > unrolled thread
| Started by | Andreas Bergmaier <andber93@web.de> |
|---|---|
| First post | 2015-06-02 21:32 +0200 |
| Last post | 2015-06-02 23:05 +0200 |
| Articles | 2 — 2 participants |
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.
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
| From | Andreas Bergmaier <andber93@web.de> |
|---|---|
| Date | 2015-06-02 21:32 +0200 |
| Subject | Re: Differences between [[Class]] and constructor |
| Message-ID | <mkl0d3$c6d$1@news.albasani.net> |
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"
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.
Bergi
[toc] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2015-06-02 23:05 +0200 |
| Message-ID | <1568741.VfgIOpCQGZ@PointedEars.de> |
| In reply to | #27963 |
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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web