yisainan / web-interview

我是齐丶先丶森,收集整理全网面试题及面试技巧,旨在帮助前端工程师们找到一份好工作!更多详见公众号「前端面试秘籍」
MIT License
2.61k stars 507 forks source link

[选择题] 45.(单选题)当我们这样做时会发生什么? #1023

Open qiilee opened 4 years ago

qiilee commented 4 years ago
function bark() {
    console.log('Woof!');
}
bark.animal - 'dog';
A:Nothing, this is totally fine!
B: SyntaxError. You cannot add properties to a function this way.
C: undefined
D: ReferenceError

答案:A

解析:

这在JavaScript中是可能的,因为函数也是对象!( 原始类型之外的所有东西都是对象)

函数是一种特殊类型的对象。您自己编写的代码并不是实际的函数。该函数是具有属性的对象,此属性是可调用的。