Preferred way to detect JSObject

20 views
Skip to first unread message

Edward Elliott

unread,
Aug 3, 2023, 10:29:47 AM8/3/23
to brython
What's the preferred way in brython to detect whether an object is a javascript object?  I'm doing this:
    import javascript
    isinstance (obj, javascript.JSObject)

But that litters the console with warning messages every time it's called (brython 3.8.9):
   "javascript.JSObject" is deprecrated. To use a Javascript object, use window.<object name> instead.

window.JSObject doesn't exist.  I searched the website, groups, and github, can't find any relevant tests for detecting js objects.  The obvious page in docs doesn't cover this.

Any suggestions?  Is there a better way to test for js objects?  I can get rid of the errors by assigning JSobject to a local variable name.  But maybe there's a better way.

FWIW the warning doesn't seem to occur in latest brython 3.11.2.  At least the online editor doesn't generate a console warning.  Maybe it was already removed / fixed.

Thanks.
Message has been deleted

Pierre Quentel

unread,
Aug 13, 2023, 2:39:34 AM8/13/23
to brython
Hello Edward,

Thanks for reporting this. There must have been a bug in previous versions but as you observed, the test with isinstance(obj, javascript.JSObject) works in the current release.

I have added a reference to javascript.JSObject in the documentation.
Reply all
Reply to author
Forward
0 new messages