New object model diagram?
Posted: 23 Nov 2020, 12:34
I keep having issues visualizing the new prototype-based object model, especially how class, class.prototype, object, and object.prototytpe all relate. I know we have this explanation from the documentation:
Is this how all the base and prototype relationships work?
I'm certainly not arguing with the structure, but the base relationships: class -> object -> class.prototype -> object.prototype always trip me up (if I, in fact, even have that right). I guess maybe because it seems different in structure than the other levels. For example, object and class have their own prototypes in their base chain, whereas no user-defined class does, right? Does my diagram reflect all these relationships correctly? Is there a better way to think about this? Thanks for any thoughts you all may have.
So given all that, let's say we have the following objects:Each class object is based on whatever class it extends, or Object if not specified. The global class object Object is based on Class.Prototype, which is based on Object.Prototype, so classes can inherit methods and properties from any of these base objects.
Code: Select all
class animal {
}
class dog extends animal {
}
wally := animal.new()
fido := dog.new()
Code: Select all
any.prototype class
(type:prototype) (type:class)
/|\ |
| (base) (base) |
| (base) (base) \|/
object.prototype <----- class.prototype <----- object
(type:prototype) (type:prototype) (type:class)
/|\ /|\
| (base) (base) |
| (base) |
animal.prototype <----- wally animal
(type:prototype) (type:animal) (type:class)
/|\ /|\
| (base) (base) |
| (base) |
dog.prototype <----- fido dog
(type:prototype) (type:dog) (type:class)