Attention: Here be dragons
This is the latest
(unstable) version of this documentation, which may document features
not available in or compatible with released stable versions of Godot.
Checking the stable version of the documentation...
JavaScriptObject
Hérite de : RefCounted < Object
A wrapper class for web native JavaScript objects.
Description
JavaScriptObject est utilisé pour interagir avec les objets JavaScript récupérés ou créés avec JavaScriptBridge.get_interface(), JavaScriptBridge.create_object(), ou JavaScriptBridge.create_callback().
extends Node
var _mon_callback_js = JavaScriptBridge.create_callback(monCallback) # Cette référence doit être gardée
var console = JavaScriptBridge.get_interface("console")
func _init():
var buffer = JavaScriptBridge.create_object("ArrayBuffer", 10) # new ArrayBuffer(10)
print(buffer) # Affiche [JavaScriptObject:OBJECT_ID]
var tableau_uint8 = JavaScriptBridge.create_object("Uint8Array", buffer) # new Uint8Array(buffer)
tableau_uint8[1] = 255
prints(tableau_uint8[1], tableau_uint8.byteLength) # Affiche "255 10"
# Affiche "Uint8Array(10) [ 0, 255, 0, 0, 0, 0, 0, 0, 0, 0 ]" dans la console du navigateur.
console.log(tableau_uint8)
# Équivalent de JavaScriptBridge : Array.from(tableau_uint8).forEach(monCallback)
JavaScriptBridge.get_interface("Array").from(tableau_uint8).forEach(_mon_callback_js )
func monCallback(args):
# Sera appellé avec les paramètres passés au callback "forEach"
# [0, 0, [JavaScriptObject:1173]]
# [255, 1, [JavaScriptObject:1173]]
# ...
# [0, 9, [JavaScriptObject:1180]]
print(args)
Note : Uniquement disponible pour la plateforme Web.