Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
164 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...