Javascript OOP / Classes - multiple instances share same data

后端 未结 2 2092
甜味超标
甜味超标 2021-01-01 01:31

I am writing some oop javascript code. I have a couple of instances of a class and have put different data into each. Unfortunately, as you will see with the example below,

2条回答
  •  温柔的废话
    2021-01-01 01:44

    For a great JavaScript inheritance example take a look at John Resig's Simple Inheritance implementation. I've been using a modified version of it for some time now. This article describes it in more detail.

    Another library that offers similar functionality is base2, but may be overkill for your needs.

    Lastly, another popular approach I've also used in the past is the Module Pattern. See this article as well for an in depth explanation of the pattern.

提交回复
热议问题