Henry asked me the other day if I could draw a picture of how my Classy Javascript works. Here’s what I came up with:
If you look at the MySubclass instance, it shows how its myattr slot is inherited up the implicit prototype chain. The Cyan things are meant to be Class objects, the Pink things are Class Prototypes, and the Orange things are Objects.

Class is not a constructor (so not a Function), it is a factory (so an Object). Instance, and the things that Class makes are constructors (so Functions). When Class makes a class, it has to copy properties into the new class and prototype (since it is not a constructor, so can’t use inheritance). I have tried to illustrate how Class copies make and addProperty to the new class and the initial property values to the new prototype. I omitted the properties that are inherited from Instance (grey-ed) from the class instances, just for simplicity, but they are there and accessible through the implicit prototype chain. All objects that obey our Class protocol will be instances of Instance, as you can see by tracing the implicit prototype chain.
Thanks for signing in, .
Now you can comment. (sign out)
(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)
You are not signed in. You need to be registered to comment on this site.
Sign in