Home > Back-end >  Why function definition is hidden from object?
Why function definition is hidden from object?

Time:01-08

Can anyone please let me know why the function declarations are hidden in JavaScript object?

const obj: any = {}
obj.normal = 'normal prop'
obj.func = function(){}
console.log(obj)

This only returns:

{
  "normal": "normal prop"
}

However, we can access obj.func obviously. But my question is why the func property is hidden while normal property is not.

Ah, I just noticed that this behavior is being seen only in TypeScript. Here's the enter image description here

CodePudding user response:

This seems to be an issue with typeScript playground as it is working correctly in https://www.mycompiler.io/

using same code

  • Related