README

#mizchi/js/builtins/proxy

Proxy API for intercepting and customizing object operations.

#Installation

Add to your moon.pkg.json:

{ "import": [ "mizchi/js", "mizchi/js/builtins/proxy" ] }

#Overview

Provides bindings for JavaScript's Proxy object, which allows you to create a wrapper around objects to intercept and customize fundamental operations.

#Usage Example

fn main {
let target = @core.Object::new()
let handler = @core.Object::new()

// Create a proxy
let proxy = @proxy.Proxy::new(target, handler)

// The proxy intercepts operations on the target object
}

#Available Features

  • Intercept property access (get/set)
  • Intercept function calls
  • Intercept property enumeration
  • Customize object behavior

#Reference

#
Proxy

#external
pub type Proxy

JavaScript Proxy

After creation with Proxy::new(), use JsImpl trait methods to interact:
  • proxy.get("key") - triggers get trap
  • proxy.set("key", value) - triggers set trap
  • proxy.delete("key") - triggers deleteProperty trap
  • proxy.hasOwnProperty("key") - triggers has trap
  • proxy._invoke(args) - triggers apply trap (for function proxies)

#
Proxy::as_any

fn Proxy::as_any(self : Proxy) ->
Any

#
Proxy::new

JS: new Proxy(target, handler) Creates a new Proxy object with optional trap handlers

Example with get trap:
let target = @core.new_object()

let _proxy = Proxy::new(@core.any(target), get=fn(_target, _prop, _receiver) {
@core.any("value")
})

Source Files