What is difference between define function by prototype and class property?

后端 未结 2 2046
醉话见心
醉话见心 2020-12-12 16:21

Follow my code,
Apple is define function by prototype.
Banana is define function by class property.

var Apple = function(){}
Apple.prototype.say = fu         


        
2条回答
  •  有刺的猬
    2020-12-12 16:55

    prototype members are like class membeprototype members are like class member, while when u define it other way its not a class member. So if you are creating lot of object of Apple all will be sharing same function, while in case of banana, every object will have their own copy of function. Think prototype in javascript as static in C#.

提交回复
热议问题