Skip to content

IJSInProcessObjectReference extended

IJSInProcessObjectReference extensions methods have been added to aid in Javascript interop. JSObject wrapped Javascript objects use the extended IJSInProcessObjectReference reference internally.

IJSInProcessObjectReference extended methods:

"identifier", aka property key, can be any type because that is what Javascript allows. - CallVoid(object identifier, arg0, ...) - Call(object identifier, arg0, ...) - CallAsync(object identifier, arg0, ...) - CallVoidAsync(object identifier, arg0, ...) - Get(object identifier) - GetAsync(object identifier) - Set(object identifier, object? value)

// Get Set
var window = JS.Get<IJSInProcessObjectReference>("window");
window.Set("myVar", 5);
var myVar = window.Get<int>("myVar");

// Synchronous calls
window.CallVoid("addEventListener", "resize", Callback.Create(() => Console.WriteLine("WindowResized")));

Create a new Javascript object using the BlazorJSRuntime (JS)

IJSInProcessObjectReference worker = JS.New("Worker", myWorkerScript);