Created
August 21, 2015 04:16
-
-
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)
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
# 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