Skip to content

Instantly share code, notes, and snippets.

@geta6
Last active December 24, 2015 19:28
Show Gist options
  • Save geta6/6850342 to your computer and use it in GitHub Desktop.
Save geta6/6850342 to your computer and use it in GitHub Desktop.
npm i node-proxy
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()
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