Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@grabcode
Created August 21, 2015 04:16
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 grabcode/9cf84172561fde2d2e33 to your computer and use it in GitHub Desktop.
Save grabcode/9cf84172561fde2d2e33 to your computer and use it in GitHub Desktop.
Underscore.js Mixin to stub an object methods - Useful when libraries are meant to work on a live environment (login exception for instance, with window.Rollbar)
# Usage: window.myObject = _.stub('myObject', {error: null, print: null})
_.mixin
stub: (objectName, props)->
res = {};
for prop of props
if props[prop]?
res[prop] = props[prop]
else
res[prop] = ((method)->
->
args = Array.prototype.slice.call(arguments)
args.unshift(objectName+" "+method+" stub")
console.log.apply(console, args)
)(prop)
res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment