Using Object.assign and Object.create for inheritance

前端 未结 3 1869
面向向阳花
面向向阳花 2020-12-12 18:29

I typically implement inheritance along the following lines.

function Animal () { this.x = 0; this.y = 0;}

Animal.prototype.locate = function() { 
  console         


        
3条回答
  •  不知归路
    2020-12-12 18:59

    Rather than "inheritance" you should think about what type of "instantiation pattern" you intend to use. They have different purposes for implementation.

    The top example is prototypal and the bottom, functional-shared. Check out this link: JS Instantiation patterns

    Also, this is non-es6 related.

提交回复
热议问题