javascript adding property to function

前端 未结 2 1355
逝去的感伤
逝去的感伤 2020-12-10 13:17

Let us say we have a function.

function Rabbit(){
  console.log(\"shiv\");
}

Now without creating an object of this function i can assign

2条回答
  •  萌比男神i
    2020-12-10 13:56

    what does this mean. do this add a variable bark to function. or do this added a property to Rabbit object

    do this add a variable bark to function - No

    or do this added a property to Rabbit object - Yes

    bark is a property of object of type Function

    even if i am not creating an object using new operator

    Rabit is already an object (of type Function). You are not creating an instance of this object, just that you are adding a property to it.

提交回复
热议问题