You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Namespace:SpawnDev.SpawnJS.JSObjects Inheritance: Static class MDN Reference:Reflect - MDN
Wraps the JavaScript Reflect built-in object. Provides static methods for interceptable JavaScript operations - the same operations targeted by Proxy handler traps. Unlike Object methods, Reflect methods return booleans for success/failure instead of throwing. Target parameters accept Union<SpawnJSObject, SpawnJSObjectReference> for maximum flexibility.
Static Methods
Property Access
Method
Return Type
Description
Get<T>(target, string propertyKey)
T
Gets a property value by string key. Like target[propertyKey].
Get<T>(target, int propertyKey)
T
Gets a property value by integer key. Like target[index].
Get<T>(target, string propertyKey, receiver)
T
Gets a property with a custom this receiver for getters.
Get<T>(target, int propertyKey, receiver)
T
Gets a property by integer key with a custom receiver.
Calls the function as a constructor (like new target(...args)).
Construct<T>(Function target, object[] argumentList, Function newTarget)
T
Calls the function as a constructor with a custom new.target.
Prototype / Extension
Method
Return Type
Description
GetPrototypeOf(target)
SpawnJSObject?
Returns the prototype of the target object, or null.
SetPrototypeOf(target, prototype)
bool
Sets the prototype. Returns true if successful.
IsExtensible(target)
bool
Returns true if new properties can be added to the target.
PreventExtensions(target)
bool
Prevents new properties from being added. Returns true if successful.
Key Enumeration
Method
Return Type
Description
OwnKeys(target)
Array
Returns an Array of the target's own property keys (strings and symbols). Ordered: non-negative integer indexes first, then string keys, then symbol keys.
Example
usingvarobj=JS.Call<SpawnJSObject>("Object.create",null);// Set and get propertiesReflect.Set(obj,"name","SpawnDev");stringname=Reflect.Get<string>(obj,"name");// "SpawnDev"// Check property existenceboolhas=Reflect.Has(obj,"name");// true// Delete a propertybooldeleted=Reflect.DeleteProperty(obj,"name");// true// Get own property keysusingvarkeyed=JS.Call<SpawnJSObject>("Object.create",null);Reflect.Set(keyed,"a",1);Reflect.Set(keyed,"b",2);usingvarkeys=Reflect.OwnKeys(keyed);Console.WriteLine($"Keys: {keys.Length}");// 2// Call a function via Reflect.Applyusingvarfn=JS.Get<Function>("Math.max");intmax=Reflect.Apply<int>(fn,null,newobject[]{1,5,3});// 5// Construct an objectusingvardateCtor=JS.Get<Function>("Date");usingvardate=Reflect.Construct<SpawnJSObject>(dateCtor,newobject[]{});