Skip to content

Instantly share code, notes, and snippets.

@ahy4
Last active July 21, 2016 07:43
Show Gist options
  • Select an option

  • Save ahy4/91ebcd4767718c02f3437484a1b8e775 to your computer and use it in GitHub Desktop.

Select an option

Save ahy4/91ebcd4767718c02f3437484a1b8e775 to your computer and use it in GitHub Desktop.
const handler = {
get: (target, name) => {
if (name in target) return target[name];
if (typeof target.methodMissing === 'function') return target.methodMissing(name);
}
};
const obj = new Proxy({
methodMissing: (name) => {
return () => `${name}は存在しませんよ!`;
}
}, handler);
console.log(obj.foo());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment