Created
December 31, 2016 04:24
-
-
Save SherryH/c38ac9ffcfabc008f6436f4c7798a920 to your computer and use it in GitHub Desktop.
Make a Spy
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
// a highly simplified version of a spy which counts total call | |
var spy = function(object, property){ | |
var origFn = object[property]; | |
var spyFn = function(){ | |
spyFn.callCount++; | |
return origin.apply(object, arguments); | |
} | |
spyFn.callCount = 0; | |
object[property] = spyFn; | |
return spyFn; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment