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


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

Re: Differences between [[Class]] and constructor

Started byThomas 'PointedEars' Lahn <PointedEars@web.de>
First post2015-06-02 22:58 +0200
Last post2015-06-02 23:07 +0200
Articles 2 — 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: Differences between [[Class]] and constructor Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-02 22:58 +0200
    Re: Differences between [[Class]] and constructor Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-06-02 23:07 +0200

#27967 — Re: Differences between [[Class]] and constructor

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2015-06-02 22:58 +0200
SubjectRe: Differences between [[Class]] and constructor
Message-ID<6733032.WIyCHQfpTH@PointedEars.de>
Stefan Ram wrote:

>   I have observed that the class ([[Class]]) name

That is _not_ the “class name”, it is the value of the internal “[[Class]]” 
property of values.  “[[Class]]” is purely a Specification mechanism and 
does not need to be implemented in a way other than to satisfy the 
algorithms of the Specification.

>   and the constructor name of an object often is the same!

Often, but not always.  As specified.

> function className( object )
> { return 0,
>   Object.prototype.toString.call( object ).
>   replace( "\[object ", "" ).replace( "\]", "" ); }

This is written shorter, less error-prone, more efficient, and actually 
readable

  (({}).toString.call(object).match(/\[object\s+(.+)\s*\]/) || [])[0]

> let n = new Number( 3.14 );

  var n = Math.PI;
 
-- 
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] | [next] | [standalone]


#27969

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2015-06-02 23:07 +0200
Message-ID<1528792.TAupHRCX4z@PointedEars.de>
In reply to#27967
Thomas 'PointedEars' Lahn wrote:

> Stefan Ram wrote:
>> function className( object )
>> { return 0,
>>   Object.prototype.toString.call( object ).
>>   replace( "\[object ", "" ).replace( "\]", "" ); }
> 
> This is written shorter, less error-prone, more efficient, and actually
> readable
> 
>   (({}).toString.call(object).match(/\[object\s+(.+)\s*\]/) || [])[0]

[1], of course.  (So much for “less error-prone” ;-))

-- 
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