If you have a singleton... and the mapping of the internal/native to the JS object, prototype is questionable... That's why I asked for a bit more code that would show that there was a new on a constructor (class) function that actually establishes the prototype connectivity.
What I'm confused myself is that not even the Object.prototype was there for you, because creating literally a blank/empty object (in JavaScript with { }) should get at least that. Obviously, with an instance, and more so a literally created singleton, it may be a bit more tricky. The prototype property (prototype object) is attached to the constructor function... getting it from an instance - like the created singleton- it goes this way: Object.getPrototypeOf(instance);. Give it a shot.
In other words, it is only an instance of Object that can have instance related methods and properties added... For extending them, save them in an extra variable and override the original one. What you for sure do not want is extend the original Object.prototype with graphics related functions.
PS: not much validated yet... and I could look way more older than in reality... ;-)
Last but not least: in Espruino, the term 'Class' is used a bit liberally... especially when coming from Smalltalk, where Classes are first class objects (instances) as well... the class Class is actually a class and creating of new classes is done by saying something like 'Class new'. In Espruino a function library - a singleton from an o-o point of view - is also called a class - and can have state (variable) and behavior (function/method) properties. In other o-o languages they would be called static methods. Anyway, JavaScript is a unique 0-o implementation all together.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
If you have a singleton... and the mapping of the internal/native to the JS object, prototype is questionable... That's why I asked for a bit more code that would show that there was a new on a constructor (class) function that actually establishes the prototype connectivity.
What I'm confused myself is that not even the Object.prototype was there for you, because creating literally a blank/empty object (in JavaScript with { }) should get at least that. Obviously, with an instance, and more so a literally created singleton, it may be a bit more tricky. The
prototype
property (prototype object) is attached to the constructor function... getting it from an instance - like the created singleton- it goes this way:Object.getPrototypeOf(instance);
. Give it a shot.In other words, it is only an instance of Object that can have instance related methods and properties added... For extending them, save them in an extra variable and override the original one. What you for sure do not want is extend the original Object.prototype with graphics related functions.
PS: not much validated yet... and I could look way more older than in reality... ;-)
Last but not least: in Espruino, the term 'Class' is used a bit liberally... especially when coming from Smalltalk, where Classes are first class objects (instances) as well... the class Class is actually a class and creating of new classes is done by saying something like 'Class new'. In Espruino a function library - a singleton from an o-o point of view - is also called a class - and can have state (variable) and behavior (function/method) properties. In other o-o languages they would be called static methods. Anyway, JavaScript is a unique 0-o implementation all together.