Skip to content

Instantly share code, notes, and snippets.

@CrypticSwarm
Created August 8, 2012 02:45
Show Gist options
  • Save CrypticSwarm/3291607 to your computer and use it in GitHub Desktop.
Save CrypticSwarm/3291607 to your computer and use it in GitHub Desktop.
Showcases a subtle problem that can occur due to getters.
var optimist = require('optimist')
optimist.demand('color')
optimist.demand('size')
optimist.argv
var optimist = require('optimist')
optimist.demand('color')
optimist.demand('size').argv
@tj
Copy link

tj commented Aug 8, 2012

plus .argv could easily just be .argv() here, I'm not bashing that API, I've used accessors plenty too, but IMO a language shouldn't even have them unless there's really a compelling reason, that's something I have yet to really see.

@CrypticSwarm
Copy link
Author

@rwldrn Agreed. However, it makes another thing that people need to keep in their minds if they copy something. Having a function (assuming it was bound to the correct object) that returned a value you could copy regularly. Not really arguing for or against, but this was something that made me do a double take when someone asked me about this situation.

Proxies will probably also have similar oddities that show up when people start making more use of them.

My thoughts are if you start using a language feature make sure you are aware of any nuances that might creep in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment