{"action":"created","issue":{"url":"https://api.github.com/repos/tvcutsem/harmony-reflect/issues/61","labels_url":"https://api.github.com/repos/tvcutsem/harmony-reflect/issues/61/labels{/name}","comments_url":"https://api.github.com/repos/tvcutsem/harmony-reflect/issues/61/comments","events_url":"https://api.github.com/repos/tvcutsem/harmony-reflect/issues/61/events","html_url":"https://github.com/tvcutsem/harmony-reflect/issues/61","id":113988346,"number":61,"title":"Cannot properly Proxy 'os' methods","user":{"login":"oNaiPs","id":374130,"avatar_url":"https://avatars.githubusercontent.com/u/374130?v=3","gravatar_id":"","url":"https://api.github.com/users/oNaiPs","html_url":"https://github.com/oNaiPs","followers_url":"https://api.github.com/users/oNaiPs/followers","following_url":"https://api.github.com/users/oNaiPs/following{/other_user}","gists_url":"https://api.github.com/users/oNaiPs/gists{/gist_id}","starred_url":"https://api.github.com/users/oNaiPs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/oNaiPs/subscriptions","organizations_url":"https://api.github.com/users/oNaiPs/orgs","repos_url":"https://api.github.com/users/oNaiPs/repos","events_url":"https://api.github.com/users/oNaiPs/events{/privacy}","received_events_url":"https://api.github.com/users/oNaiPs/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-10-29T06:19:06Z","updated_at":"2015-10-29T17:29:37Z","closed_at":null,"body":"I cannot get the following example to work:\r\n\r\n```\r\nrequire('harmonize')(['harmony_proxies']);\r\nrequire('harmony-reflect');\r\n\r\nvar os = require('os');\r\n\r\nvar p = new Proxy(os, {});\r\n\r\nconsole.log(os.type())\r\nconsole.log(p.type())\r\n```\r\n\r\nThis is what I get as output:\r\n```\r\nLinux\r\n(...)file.js:9\r\nconsole.log(p.type())\r\n              ^\r\n\r\nTypeError: Illegal invocation\r\n    at Object.<anonymous> (/home/onaips/node-lazy-require/oi.js:9:15)\r\n    at Module._compile (module.js:435:26)\r\n    at Object.Module._extensions..js (module.js:442:10)\r\n    at Module.load (module.js:356:32)\r\n    at Function.Module._load (module.js:311:12)\r\n    at Function.Module.runMain (module.js:467:10)\r\n    at startup (node.js:134:18)\r\n    at node.js:961:3\r\n```\r\n\r\nLooks like the `this` context is not being properly set. Is this a bug or I shouldn't be doing it?\r\n"},"comment":{"url":"https://api.github.com/repos/tvcutsem/harmony-reflect/issues/comments/152257795","html_url":"https://github.com/tvcutsem/harmony-reflect/issues/61#issuecomment-152257795","issue_url":"https://api.github.com/repos/tvcutsem/harmony-reflect/issues/61","id":152257795,"user":{"login":"tvcutsem","id":456763,"avatar_url":"https://avatars.githubusercontent.com/u/456763?v=3","gravatar_id":"","url":"https://api.github.com/users/tvcutsem","html_url":"https://github.com/tvcutsem","followers_url":"https://api.github.com/users/tvcutsem/followers","following_url":"https://api.github.com/users/tvcutsem/following{/other_user}","gists_url":"https://api.github.com/users/tvcutsem/gists{/gist_id}","starred_url":"https://api.github.com/users/tvcutsem/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tvcutsem/subscriptions","organizations_url":"https://api.github.com/users/tvcutsem/orgs","repos_url":"https://api.github.com/users/tvcutsem/repos","events_url":"https://api.github.com/users/tvcutsem/events{/privacy}","received_events_url":"https://api.github.com/users/tvcutsem/received_events","type":"User","site_admin":false},"created_at":"2015-10-29T17:29:37Z","updated_at":"2015-10-29T17:29:37Z","body":"By default, a proxy will pass the proxy itself as the `this` value to a forwarded method call. Since the `os.type` method expects a real `os` object as its `this` value, the call fails.\r\n\r\nTo avoid this, try overriding the proxy handler's `get` method to return a function that binds `this` to the target object that it wraps:\r\n\r\n```js\r\nvar p = new Proxy(os, {\r\n  get: function(target, name, receiver) {\r\n    if (typeof target[name] === \"function\") {\r\n     return target[name].bind(target);\r\n    }\r\n    return Reflect.get(target, name, receiver);\r\n  }\r\n})\r\n```\r\n\r\nDoes this solve your problem?"}}