Skip to content

Instantly share code, notes, and snippets.

@ricardofalasca
Last active December 21, 2018 20:45
Show Gist options
  • Save ricardofalasca/c1754910bdda26cadc38791824dca244 to your computer and use it in GitHub Desktop.
Save ricardofalasca/c1754910bdda26cadc38791824dca244 to your computer and use it in GitHub Desktop.
An usage of JavaScript Global Object "Proxy" to create a magical object that can receive any method call - useful for Fake/Mocking objects
var magicalObj = (function magicalMethod() {
return new Proxy(new Object(), {
get(target, propertyName, receiver) {
const theMethod = (target.propertyName) ? target.propertyName : function () { return true }
return function (...args) { return theMethod.apply(this, args) }
}
})
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment