poor-mans-proxy

1.0.0 • Public • Published

poor-mans-proxy Build Status npm version

ES6 Proxy pollyfill, with many limitations

This is a best effort polyfill, as most of Proxy's functionality can not be implemented in userland.

Install

npm install poor-mans-proxy --save

Usage

require('poor-mans-proxy');
 
var obj = {
    name: 'Obj'
};
 
var proxy = new Proxy(obj, {
    get: function(target, prop, receiver) {
        console.log(prop, 'accessed');
        return target[prop];
    }
});
 
console.log(proxy.obj);
 
// : name accessed 
// : Obj

API

new Proxy(target [, handler])

Creates a Proxy of the target object, with handlers defined by the handler object.

target Object|Function Object or Function to proxy.

handler Object Handler definitions.

.get = function(target, property, receiver) The handler.get() method is a trap for getting a property value. See Get

.set = function(target, property, value, receiver) The handler.set() method is a trap for setting a property value. See Set

.apply = function(target, thisArg, argumentsList) The handler.apply() method is a trap for a function call (if target is a function). See Apply

The target object's properties must be defined before calling new Proxy(). Dynamic properties are not supported.

Test

npm install
npm test

Dependencies (1)

Dev Dependencies (3)

Package Sidebar

Install

npm i poor-mans-proxy

Weekly Downloads

135

Version

1.0.0

License

MIT

Last publish

Collaborators

  • bealearts