javascript函数如何在其中具有属性? [英] How do javascript functions have properties in them?

查看:36
本文介绍了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);

这篇关于javascript函数如何在其中具有属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆