javascript - ECMAScript 6 child class prints with parents name -


when console.log(object) expect see name of object's class. seems rather unexpected child class carries name of parent.

"use strict";  class parent {   constructor () {   } } class child extends parent {   constructor () {     super();   } } class grandchild extends child {   constructor () {     super();   } }  var grandchild = new grandchild();  console.log(grandchild); // parent {} console.log(grandchild.constructor.name); // grandchild console.log(grandchild instanceof parent); // true console.log(grandchild instanceof child); // true console.log(json.stringify(grandchild)); // {} 

is intended behaviour? console.log that's messing up, or javascript consider instances of descendant class be, first , foremost, instance of root level class?

console not standard, can see in mdn entry. standard way class name of instance in es6 use instance.contructor.name. stated in the spec.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -