GitHub - KoryNunn/potatoscript: how js works explained with potatos

1 min read Original article ↗

potatoscript

Implementing javascript features that often confuse people.

potatoscript will implement js features as well as possible, in JS, with potatos

Because we can't use the identifiers used by javascript, we will use our own:

instead of proto we will use potato

and we will call this potatotypical inheritance.

new

new Constructor():

  1. creates a new, plain object. Assigns its .__proto__ to Constructor.prototype
  2. applies the new object, and the arguments to the Constructor
  3. returns the result of the apply IF it results in an Object, otherwise returns the new object.

Prototypical version:

implementation

test

Potatotypical version:

implementation

Tested via tests for the other potatotypical features.

prototypical get via key

object.foo:

  1. if object has the key of foo, returns the value at object.foo
  2. If not, and object.__proto__.__proto__ exists, passes object.__proto__ to step 1.
  3. If there are no more __proto__s in the chain, returns undefined.

Potatotypical version:

implementation

test

instanceof

object instanceof Constructor:

  1. Returns true if object has a .__proto__ that is Constructor.prototype
  2. If not, and object.__proto__.__proto__ exists, passes object.__proto__ to step 1.
  3. If there are no more __proto__s in the chain, returns false.

Potatotypical version:

implementation

test