When creating an object using direct initialization and showing it in the console, the engine fails to assign it any type. This is not surprising, as the console considers displaying Object
to be of little value. However, when a constructor function is used, the type is indeed assigned:
let obj1 = { d1: true, m1: function() { return 'MSG' } };
console.log(obj1);
let obj2 = new function SomeFunc() { };
obj2.anyField = 50;
console.log(obj2);
https://i.sstatic.net/KEARf.png
Is there an easy way to assign a type to an object directly during initialization without needing to define a function? Perhaps something akin to
__proto__: { constructor: { name: 'abcd' } }
exists that can achieve this effect? Ideally, a simpler solution would be preferred.