Skip to content

Instantly share code, notes, and snippets.

@thomasfr
Last active June 22, 2017 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasfr/d4568e4e933916777a35b9e33edfd385 to your computer and use it in GitHub Desktop.
Save thomasfr/d4568e4e933916777a35b9e33edfd385 to your computer and use it in GitHub Desktop.
Example for "Extract object structure by usage". This would help refactoring an old code base where the structure of some arguments are not exactly known, or when testing and it is necessary to mock a dependency and you have to pass a object with the same structure for instance
function foo (options, meta, callback) {
console.log(options.propOne)
console.log(options.propTwo[0].foo)
console.log(options.propTwo[0].bar)
console.log(options.propThree.subProp.hello)
meta.foo = 'bar'
}
// A IDE could extract the structure of `options` as JSON
// and copy that structure into the clipboard (functionality could be found in a context menu for example)
{
propOne: null,
propTwo = [
{foo:null, bar:null}
],
propThree: {
subProp: {
hello: null
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment