mirror of
https://github.com/godotengine/godot-docs.git
synced 2025-12-31 17:49:03 +03:00
61 lines
2.8 KiB
ReStructuredText
61 lines
2.8 KiB
ReStructuredText
:github_url: hide
|
|
|
|
.. DO NOT EDIT THIS FILE!!!
|
|
.. Generated automatically from Godot engine sources.
|
|
.. Generator: https://github.com/godotengine/godot/tree/master/doc/tools/make_rst.py.
|
|
.. XML source: https://github.com/godotengine/godot/tree/master/doc/classes/JavaScriptObject.xml.
|
|
|
|
.. _class_JavaScriptObject:
|
|
|
|
JavaScriptObject
|
|
================
|
|
|
|
**Inherits:** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
|
|
|
|
A wrapper class for web native JavaScript objects.
|
|
|
|
.. rst-class:: classref-introduction-group
|
|
|
|
Description
|
|
-----------
|
|
|
|
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>`.
|
|
|
|
\ **Example:**\
|
|
|
|
::
|
|
|
|
extends Node
|
|
|
|
var _my_js_callback = JavaScriptBridge.create_callback(myCallback) # This reference must be kept
|
|
var console = JavaScriptBridge.get_interface("console")
|
|
|
|
func _init():
|
|
var buf = JavaScriptBridge.create_object("ArrayBuffer", 10) # new ArrayBuffer(10)
|
|
print(buf) # prints [JavaScriptObject:OBJECT_ID]
|
|
var uint8arr = JavaScriptBridge.create_object("Uint8Array", buf) # new Uint8Array(buf)
|
|
uint8arr[1] = 255
|
|
prints(uint8arr[1], uint8arr.byteLength) # prints 255 10
|
|
console.log(uint8arr) # prints in browser console "Uint8Array(10) [ 0, 255, 0, 0, 0, 0, 0, 0, 0, 0 ]"
|
|
|
|
# Equivalent of JavaScriptBridge: Array.from(uint8arr).forEach(myCallback)
|
|
JavaScriptBridge.get_interface("Array").from(uint8arr).forEach(_my_js_callback)
|
|
|
|
func myCallback(args):
|
|
# Will be called with the parameters passed to the "forEach" callback
|
|
# [0, 0, [JavaScriptObject:1173]]
|
|
# [255, 1, [JavaScriptObject:1173]]
|
|
# ...
|
|
# [0, 9, [JavaScriptObject:1180]]
|
|
print(args)
|
|
|
|
\ **Note:** Only available in the Web platform.
|
|
|
|
.. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
|
|
.. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
|
|
.. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
|
|
.. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
|
|
.. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
|
|
.. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
|
|
.. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`
|