Created
November 7, 2014 03:23
-
-
Save hacke2/720c70ec10b090d035ef to your computer and use it in GitHub Desktop.
Revisions
-
hacke2 created this gist
Nov 7, 2014 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,71 @@ Function.prototype.before = function(func) { var that = this; return function() { //debugger if(func.apply(this, arguments) === false) { return false; } return that.apply(this, arguments); } } Function.prototype.after = function(func) { var that = this; return function() { var ret = that.apply(this, arguments); if(ret === false) { return false; } func.apply(this, arguments); return ret; } } function logTime (func, funcName) { return func = (function() { var d; return func.before(function() { d = +new Date(); }).after(function() { console.log(+new Date() - d, funcName); }); })() } function logBefore() { if(window.console) { window.console.log(1); } } function logAfter() { if(window.console) { window.console.log(3); } } function func(msg) { console.info(msg); } function func2(msg) { var temp = 0 sleep(1000) return temp; } function sleep(maxtime) { var now = +new Date(); while(true) { if(+new Date() - now > maxtime) { break; } } } /*func = func.before(logBefore).after(logAfter); func(2) //1,2,3*/ /*func2 = logTime(func2, "fuc") func2()*/