Meaning of prototype in javascript

前端 未结 6 978
别跟我提以往
别跟我提以往 2021-02-02 12:10

I wrote short code of inheritance of reader from Person:



        
6条回答
  •  -上瘾入骨i
    2021-02-02 12:48

    In class-based words the difference between declaring a function via prototype and this would be something like this:

    prototype:

    the function of the instance would look like this:

    somefunc = function(){super()/*call the function of the super-class*/};
    

    this:

    the function of the instance would look like this:

    somefunc = function(){/* Do same stuff as in the prototype func declared */};
    

    Now changing the function on the prototype will have no effect on the instance.

提交回复
热议问题