javascript函数如何在其中具有属性?

问题描述:

function myFunc(){
    console.log(myFunc.message);
}
myFunc.message = "Hi John";

myFunc();

在-

Answer: 'Hi John'

函数myFunc如何具有属性message? typeof myFunc产生功能",并且console.log(myFunc)显示功能内容(不带属性message).

How is the function myFunc have the property message on it? typeof myFunc results in "function" and console.log(myFunc) displays the function content (without the property message on it).

以上内容如何运作? JavaScript内部的函数是对象吗?

How does the above work? Is a function in JavaScript internally an object?

注意-我知道函数具有其他参数,例如原型和长度.但是我不确定这些如何实现.

Note - I am aware that functions have other parameters like prototype and length on them. But I am not sure how these are implemented as well.

其他查询- 由于console.log(myFunc)不显示对象属性,因此如何列出功能对象的所有属性?

Additional query - Since console.log(myFunc) does not show the object properties, how do I list all the properties of a function object?

以上内容如何运作? javascript中的函数在内部是对象吗?

How does the above work? Is function in javascript internally an object?

function example() {};

console.log(example instanceof Object);