JavaScriptObject
本地JavaScript对象的封装类。
描述
JavaScriptObject用于与通过JavaScript.get_interface、JavaScript.create_object或JavaScript.create_callback检索或创建的JavaScript对象交互。
例:
extends Node
var _my_js_callback = JavaScript.create_callback(self, "myCallback") # This reference must be kept
var console = JavaScript.get_interface("console")
func _init():
var buf = JavaScript.create_object("ArrayBuffer", 10) # new ArrayBuffer(10)
print(buf) # prints [JavaScriptObject:OBJECT_ID]
var uint8arr = JavaScript.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 JavaScript: Array.from(uint8arr).forEach(myCallback)
JavaScript.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)
注意: 只在HTML5平台上可用。