Search code examples
gnome-shellgjs

GJS gnome-shell exception error, how to overcome this error


I would like to learn what this error message is.

imports.ui.dateMenu.DateMenuButton.prototype.hide()

When I run above in lookingGlass, I get below error

<exception Error: Can't convert to pointer on .Gjs_ui_dateMenu_DateMenuButton.prototype; only on instances>

Can any one explain in detail.

Thanks.


Solution

  • JavaScript has prototypal inheritance — meaning that DateMenuButton.prototype is an object that contains DateMenuButton's methods, but it is not a DateMenuButton itself. So when you call DateMenuButton.prototype.hide(), you are calling DateMenuButton's hide() method on an object that is not a DateMenuButton. This will give you an error. The error message is not particularly clear but "can't ___ on prototype, only on instances" is a hint about what's going on.

    To call this method, you will need an actual DateMenuButton object.

    Here is some further reading material on prototypal inheritance: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Inheritance_and_the_prototype_chain