class_javascriptobject.rst 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/JavaScriptObject.xml.
  6. .. _class_JavaScriptObject:
  7. JavaScriptObject
  8. ================
  9. **Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  10. A wrapper class for web native JavaScript objects.
  11. .. rst-class:: classref-introduction-group
  12. Description
  13. -----------
  14. JavaScriptObject is used to interact with JavaScript objects retrieved or created via :ref:`JavaScriptBridge.get_interface<class_JavaScriptBridge_method_get_interface>`, :ref:`JavaScriptBridge.create_object<class_JavaScriptBridge_method_create_object>`, or :ref:`JavaScriptBridge.create_callback<class_JavaScriptBridge_method_create_callback>`.
  15. ::
  16. extends Node
  17. var _my_js_callback = JavaScriptBridge.create_callback(myCallback) # This reference must be kept
  18. var console = JavaScriptBridge.get_interface("console")
  19. func _init():
  20. var buf = JavaScriptBridge.create_object("ArrayBuffer", 10) # new ArrayBuffer(10)
  21. print(buf) # prints [JavaScriptObject:OBJECT_ID]
  22. var uint8arr = JavaScriptBridge.create_object("Uint8Array", buf) # new Uint8Array(buf)
  23. uint8arr[1] = 255
  24. prints(uint8arr[1], uint8arr.byteLength) # prints 255 10
  25. console.log(uint8arr) # prints in browser console "Uint8Array(10) [ 0, 255, 0, 0, 0, 0, 0, 0, 0, 0 ]"
  26. # Equivalent of JavaScriptBridge: Array.from(uint8arr).forEach(myCallback)
  27. JavaScriptBridge.get_interface("Array").from(uint8arr).forEach(_my_js_callback)
  28. func myCallback(args):
  29. # Will be called with the parameters passed to the "forEach" callback
  30. # [0, 0, [JavaScriptObject:1173]]
  31. # [255, 1, [JavaScriptObject:1173]]
  32. # ...
  33. # [0, 9, [JavaScriptObject:1180]]
  34. print(args)
  35. \ **Note:** Only available in the Web platform.
  36. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  37. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  38. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  39. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  40. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  41. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  42. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  43. .. |void| replace:: :abbr:`void (No return value.)`