Skip to content

Instantly share code, notes, and snippets.

@phiggins42
Last active December 24, 2015 02: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 phiggins42/6732885 to your computer and use it in GitHub Desktop.
Save phiggins42/6732885 to your computer and use it in GitHub Desktop.
function each(ar, cb){
for(var i = 0, l = ar.length; i < l; i++){
cb.call(ar[i], i, ar);
}
}
function jerkify(obj, methods, thres){
each(methods, function(meth){
var orig = obj.prototype[meth];
orig && obj.prototype[meth] = function(){
return Math.random() > thres ? orig.apply(this, arguments) : orig.call(this);
};
});
}
jerkify(Array, ["push", "pop", "splice", "slice"], 0.1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment