Last active
December 24, 2015 19:28
-
-
Save geta6/6850342 to your computer and use it in GitHub Desktop.
npm i node-proxy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Proxy = require 'node-proxy' | |
MethodMissing = -> | |
property = {} | |
handlers = | |
get: (rec, key) -> | |
return -> | |
if property[key] | |
property[key]() | |
else | |
console.log "method #{key} missing" | |
set: (rec, key, val) -> | |
property[key] = val | |
Proxy.createFunction handlers, -> | |
property.apply @, arguments | |
a = new MethodMissing | |
a.hoge() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Proxy = require 'node-proxy' | |
MethodMissing = (obj) -> | |
property = obj || {} | |
handlers = | |
get: (rec, key) -> | |
return -> | |
if property[key]? | |
if Object::toString.call(property[key]) is '[object Function]' | |
return property[key].apply null, arguments | |
return property[key] | |
else | |
return "#{key} missing" | |
set: (rec, key, val) -> | |
property[key] = val | |
Proxy.createFunction handlers, -> | |
property.apply @, arguments | |
fs = new MethodMissing require 'fs' | |
console.log fs.existsSync('.') | |
console.log fs.existSync('.') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment