UNPKG

niim

Version:
33 lines (28 loc) 729 B
#! /usr/bin/env node const real = [1,2,3,4,5,6,7,8,9, {hello: 'world'}]; var px = new Proxy(real, { get: function(target, prop) { if (typeof prop === 'symbol') return target[prop]; switch(typeof target[prop]) { case 'undefined': case 'number': case 'string': case 'boolean': case 'function': case 'symbol': return target[prop]; /* immutable */ case 'object': return {...target[prop]}; default: throw new Error('I have no idea what to do with', `(${prop})`); } }, set: function(target, prop, value) { return false; } }); console.log(px.filter((x) => x > 3)); console.log(real); console.log(px); console.log(px.splice(1,2));