function say_yes(){
console.log("yes")
}
Obj={}
Obj=say_yes
Obj.something="something"
Obj.nothing="nothing"
在浏览器中
在上面的代码中,如果i console.log(Obj)
,则给出函数表达式
在上面的代码中,如果i console.log(Obj.something)
或console.log(Obj.nothing)
给出属性值。
当我打电话给Obj()
时,它控制台"yes"
在节点上 在上面的代码中,如果我console.log(Obj)给出
{ [Function: say_yes] something: 'something', nothing: 'nothing' }
在上面的代码中,如果i console.log(Obj.something)
或console.log(Obj.nothing)
给出属性值。
当我致电Obj()
时,它会控制台"yes"
我真的很困惑,它是Obj的功能吗?是一个对象吗?
在看到express框架的module.exports
的源代码后,我对此感到怀疑。
有人可以消除我的疑虑吗。.
答案 0 :(得分:0)
javascript中的所有函数实际上都是一流的对象。可以调用那些功能对象。您可以在这里阅读:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions