在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ 函數聲明的問題

函數聲明的問題

變量聲明中

    var fn = function fn2() {}
    
    console.log(fn) // function
    console.log(fn2) // Uncaught ReferenceError: fn2 is not defined

這里的fn2為什么是not defined? 是因為在fn2自己的作用域中么?

回答
編輯回答
孤客

javascript the definitive guide 8.1

An identifier that names the function. The name is a required part of function declaration statements: it is used as the name of a variable, and the newly defined function object is assigned to the variable. For function definition expressions, the name is optional: if present, the name refers to the function object only within the body of the function itself.

就是說,「賦值函數定義式」中的 identifier(函數名)是可選的,即使提供,也只能在函數體內引用;

2018年1月26日 03:00
編輯回答
解夏

fn2只能在fn2中才能引用的到

2018年5月29日 09:14
編輯回答
她愚我

function fun2(){}
var fn = fn2
console.log(fn)
console.log(fn2)

2017年5月1日 22:00