{"id":13473030,"url":"https://github.com/GoogleChrome/proxy-polyfill","last_synced_at":"2025-03-26T17:31:41.221Z","repository":{"id":54158364,"uuid":"52118963","full_name":"GoogleChrome/proxy-polyfill","owner":"GoogleChrome","description":"Proxy object polyfill","archived":false,"fork":false,"pushed_at":"2024-06-27T15:22:42.000Z","size":212,"stargazers_count":1139,"open_issues_count":11,"forks_count":175,"subscribers_count":29,"default_branch":"master","last_synced_at":"2025-03-11T21:17:23.826Z","etag":null,"topics":["polyfill","proxy","trap"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/GoogleChrome.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-02-19T21:53:08.000Z","updated_at":"2025-02-19T23:59:57.000Z","dependencies_parsed_at":"2024-01-14T10:20:32.859Z","dependency_job_id":"8c3332a1-fc51-463a-9347-b10a3b14c77b","html_url":"https://github.com/GoogleChrome/proxy-polyfill","commit_stats":{"total_commits":95,"total_committers":12,"mean_commits":7.916666666666667,"dds":"0.28421052631578947","last_synced_commit":"ec21e2073a29be7625f3cb9913de823805473f60"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleChrome%2Fproxy-polyfill","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleChrome%2Fproxy-polyfill/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleChrome%2Fproxy-polyfill/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/GoogleChrome%2Fproxy-polyfill/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/GoogleChrome","download_url":"https://codeload.github.com/GoogleChrome/proxy-polyfill/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243818195,"owners_count":20352629,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["polyfill","proxy","trap"],"created_at":"2024-07-31T16:01:00.064Z","updated_at":"2025-03-26T17:31:41.194Z","avatar_url":"https://github.com/GoogleChrome.png","language":"JavaScript","readme":"*Please note that this polyfill is now in maintenance mode, as of Jan, 2023. We are not planning to add more features or enhancements.*\n__________\n\nThis is a polyfill for the `Proxy` object, part of ES6.\nSee the [MDN docs](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Proxy) or [Introducing ES2015 Proxies](https://developers.google.com/web/updates/2016/02/es2015-proxies) for more information on `Proxy` itself.\nUnlike other polyfills, this does not require `Object.observe`, [which is no longer supported anywhere](https://www.google.com/search?q=object.observe+deprecated).\n\n⚠️ Note that Firefox, Chrome, Safari 10+ and Edge support `Proxy` natively.\nYou don't need this if you're only targeting these modern browsers.\n\nThe polyfill supports just a limited number of proxy 'traps'.\nIt also works by calling [seal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal) on the object passed to `Proxy`.\nThis means that the properties you want to proxy **must be known at creation time**.\n\nAdditionally, your objects' prototypes will be snapshotted at the time a proxy is created.\nThe properties of your objects can still change - you're just unable to define new ones.\nFor example, proxying unrestricted dictionaries is not a good use-case for this polyfill.\n\nCurrently, the following traps are supported-\n\n* get\n* set\n* apply\n* construct\n\nThe `Proxy.revocable` [method](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/revocable) is also supported, but only for calls to the above traps.\n\nThis has no external dependencies.\nSkip down to [usage](#usage) to get started.\n\n# Example\n\nThe most compelling use case for `Proxy` is to provide change notifications.\n\n```js\nfunction observe(o, callback) {\n  return new Proxy(o, {\n    set(target, property, value) {\n      callback(property, value);\n      target[property] = value;\n    },\n  });\n}\n\nconst x = {'name': 'BB-8'};\nconst p = observe(x, (property, value) =\u003e console.info(property, value));\np.name = 'BB-9';\n// name BB-9\n```\n\nYou can extend this to generate change notifications for anywhere in an object tree-\n\n```js\nfunction observe(o, callback) {\n  function buildProxy(prefix, o) {\n    return new Proxy(o, {\n      set(target, property, value) {\n        // same as above, but add prefix\n        callback(prefix + property, value);\n        target[property] = value;\n      },\n      get(target, property) {\n        // return a new proxy if possible, add to prefix\n        const out = target[property];\n        if (out instanceof Object) {\n          return buildProxy(prefix + property + '.', out);\n        }\n        return out;  // primitive, ignore\n      },\n    });\n  }\n\n  return buildProxy('', o);\n}\n\nconst x = {'model': {name: 'LEAF'}};\nconst p = observe(x, (property, value) =\u003e console.info(property, value));\np.model.name = 'Tesla';\n// model.name Tesla\n```\n\n## Adding new properties\n\nThe following line will fail (with a `TypeError` in strict mode) with the polyfill, as it's unable to intercept _new_ properties-\n\n```js\np.model.year = 2016;  // error in polyfill\n```\n\nHowever, you can replace the entire object at once - once you access it again, your code will see the proxied version.\n\n```js\np.model = {name: 'Falcon', year: 2016};\n// model Object {name: \"Falcon\", year: 2016}\n```\n\nFor a similar reason, this polyfill can't proxy `Array` objects very well - but you can replace them all at once.\n\n# Usage\n\nInstall via your favourite package manager as `proxy-polyfill`.\n\n## To polyfill Proxy everywhere\n\nYou should either:\n\n* include `proxy-polyfill` into your build system (just require it directly, it doesn't export anything), or\n* import the `proxy.min.js` file directly.\n\nThis is the recommended approach and works on the web, in Node, or React Native.\n\n**Do not** import `./src/proxy.js` in old browsers directly, as it uses modern JavaScript features.\nIt needs to be compiled, which is why we have the `proxy.min.js` file.\n\n## To consume the polyfill as a function\n\nThis is an advanced pattern.\nRequires `./src/proxy.js`, which exports a proxy polyfill _builder_ function in commonJS.\n\n```js\n// commonJS require\nconst proxyPolyfill = require('proxy-polyfill/src/proxy')();\n\n// Your environment may also support transparent rewriting of commonJS to ES6:\nimport ProxyPolyfillBuilder from 'proxy-polyfill/src/proxy';\nconst proxyPolyfill = ProxyPolyfillBuilder();\n\n// Then use...\nconst myProxy = new proxyPolyfill(...);\n```\n\n# Support\n\nThe polyfill supports browsers that implement the full [ES5 spec](https://kangax.github.io/compat-table/es5/), such as IE9+ and Safari 6+.\nIt may work in other non-browser environments too.\n","funding_links":[],"categories":["JavaScript","目录"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGoogleChrome%2Fproxy-polyfill","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FGoogleChrome%2Fproxy-polyfill","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FGoogleChrome%2Fproxy-polyfill/lists"}