JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2080
  • Score
    100M100P100Q126019F
  • License ISC

The Class Proxy is used to define custom behavior for fundamental operations (e.g. property lookup, assignment, enumeration, function invocation, etc).

Package Exports

  • class-proxy

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (class-proxy) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

class-proxy

The Class Proxy is used to define custom behavior for fundamental operations (e.g. property lookup, assignment, enumeration, function invocation, etc).

npm install class-proxy

api

demo

import createClassProxy from 'class-proxy';
import { createClassProxy } from 'class-proxy';

var createClassProxy = require("class-proxy/node");
import { implementation as URLImpl } from 'whatwg-url/lib/URL-impl';

let URLImplProxy2 = createClassProxy(URLImpl, {
    get(target, name)
    {
        return target[name];
    },
    set(target, prop, value, receiver)
    {
        if (prop == '_query')
        {
            value._url = target;

            console.log(value);
        }

        target[prop] = value;
        return true;
    },
    ownKeys(target): string[]
    {
        return [
            'href',
            'origin',
            'protocol',
            'username',
            'password',
            'host',
            'hostname',
            'port',
            'pathname',
            'search',
            'hash',
            'searchParams',
        ];
    },
    getOwnPropertyDescriptor(target, prop)
    {
        return {
            value: target[prop],
            enumerable: this.ownKeys(target).includes(prop),
            configurable: true,
        };
    },
    construct(target, args)
    {
        if (typeof args[0] == 'string')
        {
            return new target([args[0]]);
        }

        return new target(...args);
    }
});