loading...

Architecture of Prototype Inheritance in JavaScript

wentout profile image went ・6 min read

I'm stuck. Yes, I stuck. I did it the first once, then second, third and finally just ... stuck. It blows my mind, though, I think this should be coded somehow, yes. It might be the general purpose library or command line interface, whatever. It might combine the way of usage. And it is about how we code algorythms, for sure we shall live with it.

For the vista of re-vision let assume it is a secret that Algorithm is a "sequence" ... of of well-defined, computer-implementable instructions ... and so on ...

And there is Topological sorting and all the way we do instructions is a pipline of data processing.

And what if there is a thing we might avoid thinking of as of a sequence? Undoubtedly from well known Black hole Information Paradox we might probably review our understanding of "everything" as a "sequence". But from the other side there is Poincaré conjecture and there is an impact to the solutions where we should throw out the Ideas with broken Topology.

In an attempt to prepare us for the next step here is other nice beginner's topic: Composition over Inheritance, and here is same title video from Fun Fun Functions.

And the hidden question there:
Is Composition a Sequence or Not?

Well... we might obviously converse it is a technique to combine reusable sequence part of algorithms to make them work more efficiently in a whole structure.

« But it's not that easy when your soul is torn in two »

I mean, reusable parts is a great idea, all that stuff which reusably Controls the flow of our code: Loops, or Recursions or... nevermind, they are made for Greater Good. Generators with Promises and all that async'ish stuff are great helpers.

Though when we will climb up and down on the "ladder of abstraction" probably we will see the whole thing, but there might be hidden "black hole's event horisons" which we will probably hardly overcome with thinking of code "reusability".

I mean "reusability" is not a thing, but "sequence" is a Thing, very natural thing with a lot of characteristics, for example "State" or "Observability" and "Measurements". And all this sequenced async stuff is done narrowing calculations with raw data or even with well prepared Information or odd it might be "of the bit" eventually just feelings of the kinds.

Then well, when we shall connect that feelings of our mind with sequence, can we get the idea of beauty? Shold we reuse it? Or should we repeat it recursively for whatever this might be meaning then?

I don't even understand what I'm writing, this might be complete noise, or one of the definitions of "42". And indeed it is proven by Gödel's incompleteness theorems.

And 42 itself is a serial number of multiplier symbol of ASCI symbols table, which is then connected to "...ad Astra" in Latin, and then to Astarte or Ishtar, the godess of love,
power and war from the Bronze Age. And she is then an avatar of Shakti or Pravati in Hinduism.

And here we might think Cosmos and topology and time are connected to algorythms and lifecycle of data.

And what if we can combine all this flavors to a Chain of responsibility with declarative Meta-programming?

This definetely might be coded...
We indeed can craft code allowing us to aid information retention during data lifecycle... But the question is still there: what is a Sequence?

What is of that piece of minimal abstraction we should re-use avoiding of Entropy? Where information retention is not so enough? And should that hidden piece be sacred or not?

Describing algorythm as a Narrative story and Plot we might convince then the aspect of chronological order of the events in the meaning of Chronotope is very tightly coupled with the concept of Grammatical modifier in the meaning of Function composition and Object composition at the sequence of time.

And the concept of Modifier in Software Engineering describes exactly what we are seeking for. There is a lot of them, here are just a few of may other examples:

  • for Access: Private, Static, Protected, Internal ...
  • for Type: Signed, Unsigned, Short, Long ...
  • Behaviour: 'use strict';, "... throws" to be "thrown"

And each one of them describes an answer to the question "what will happen": so, this is a setting for Chronotope. Despite of Type Systems answering the question "what is it", modifiers answers the questions "how are they". So shouldn't then there be the a question "when they are", and "why they are" and even "whose are they" in Runtime?

For sure, the answers are "Yes" for all that questions, it is just what we are doing as a developers. Crafting our algorythms we describe the answers to that questions, we always make:

  • extracting or consuming data,
  • transforming data from one form to the other,
  • and then we might be storing the data or loading it somewhere else.

And seems nothing is wrong here, but... why then we have a lot of bugs everyday, isn't this is a point we might be missing something? Seems there might be some hidden review point and we shall find it for the Greater Good in a memory of the past.

Indeed, then here I stuck seeking for solution.

And then I remembered... It was far ago, more than 20 years, as if should it be me getting back to the past as mystic re-vision of my own future. And I got it just few month ago, obviously by a chance. To be honest it was not me who found it. I just felt it is what am I seeking for. And even more, I felt it only now, passing 20 years of seeking for nothing, being able to touch it anywhen. I can't remember that day well, it was a moment of summer obligatory computer classes after my first University term. There was a file leaved by somewone else on my clasroom's desktop with MS Windows NT. And I do remember when I saw that code I felt like complete dumb. I was unable to get the idea then, though it was clear enough, and I can describe it very well even now. There was Factory function, which was making a function and then that function returned to the variable was constructed, something like this:

    // to the glory of Mnemosyne
    function Factory (previous) {
      function MyConstructor (state) {
        this.state = state;
      };
      MyConstructor.prototype = previous;
      return MyConstructor;
    };

    var initial = { state: 1 };
    var Constructor_1 = Factory(initial);
    var next1 = new Constructor_1(2);
    var Constructor_2 = Factory(next1);
    var next2 = new Constructor_2(3);

What have I missed was the prototype keyword and the meaning what it was doing. There was no debugging tools that times, and I was able to understand the final .state is 3 but it was hidden from me that all previous states are there, inside of Prototype Chain of next1 and next2:

state of inheritance

And inspite I noticed the name of Mnemosyne, cause it was very close to Mnemonic and I knew this word from books of tricks and magic, I was unable to connect it with algorythm itself, thinking it was just a joke for some naughty girl.

Having very few competence, undoubtedly I thought the code is just garbage, but it was indeed Genius Masterpiece...

Posted on by:

wentout profile

went

@wentout

JavaScript enthusiast. Computerman. Teapot Systems Administrator.

Discussion

pic
Editor guide