class_javascriptobject.rst 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. # Prints "Uint8Array(10) [ 0, 255, 0, 0, 0, 0, 0, 0, 0, 0 ]" in the browser's console.
  26. console.log(uint8arr)
  27. # Equivalent of JavaScriptBridge: Array.from(uint8arr).forEach(myCallback)
  28. JavaScriptBridge.get_interface("Array").from(uint8arr).forEach(_my_js_callback)
  29. func myCallback(args):
  30. # Will be called with the parameters passed to the "forEach" callback
  31. # [0, 0, [JavaScriptObject:1173]]
  32. # [255, 1, [JavaScriptObject:1173]]
  33. # ...
  34. # [0, 9, [JavaScriptObject:1180]]
  35. print(args)
  36. \ **Note:** Only available in the Web platform.
  37. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  38. .. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
  39. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  40. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  41. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  42. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  43. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  44. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
  45. .. |void| replace:: :abbr:`void (No return value.)`