I am still involved, but recently I changed the field in which I want to work in web development. Therefore, programming is not new for me, but I have never looked twice in javascript.
I am trying to learn quickly, but I am confused about the different inheritance patterns used in javascript. I looked at the classic prototype chain where the .prototype task is set by the programmer (I think this is usually called the prototype). Then I read many blogs and articles about OLOO and its advantages regarding simplicity.
So, I tried a little coding of the sample and, exploring a good approach, came up with code that I canβt fit into either of these two categories.
I made a fiddle if I want to see: http://jsfiddle.net/HB7LU/19377/
For someone else, this is basically my code:
function Parent() { return { array: [], add: function(element) { this.array.push(element + this.array.length.toString()); }, getAll: function() { return this.array; }, }; }; function Child() { return Object.assign(Parent(), { removeAllButOne: function() { this.array.splice(1); } }); }; foo = Parent(); foo.add('foo'); bar = Child(); bar.add('bar'); foo.add('foo'); bar.add('bar'); bar.removeAllButOne();
Hopefully someone can clarify what I did here and what disadvantages I will use using this method. I know that this cannot be OLOO, because OLOO relies on a simple Object.create(...); to create new objects.
EDIT: violin link was broken, sorry
javascript
swent
source share