I was reading about Object Oriented JS, and trying to understand whether prototype based inheritance is best in my case. I just read Eric Elliot post on the superiority of this method over classical pattern here
In my case, I have to model, say 10,000 instances of a type or class called Shape . I need each object hold on to its state, say size. Would using clone to extend the prototype (2nd method in Eric's post) causes the methods to clone too?? From his example,
var proto = {
hello: function hello() {
return 'Hello, my name is ' + this.name;
}
};
var george = _.extend({}, proto, {name: 'George'});
does in the above case, creating 10,000 instance would clone hello into all the instances?
If that is the case, what is the best approach for me. My type/class holds 10 primitive values, and more act as a holder of data than abstracting behavior. Requirements,
- Each instance hold on to private data.
- Have some common methods to get/set those data (or just properties)
- Easy to convert to Json