fork(1) download
  1. process.stdin.resume();
  2. process.stdin.setEncoding('utf8');
  3.  
  4. // your code goes here
  5.  
  6. var console = {
  7. log: function(s) {
  8. process.stdout.write(s+"\n");
  9. },
  10. };
  11.  
  12. var count_hash = {};
  13.  
  14. function callcounter(func) {
  15. count_hash[func.name] = 0;
  16. return function() {
  17. count_hash[func.name] += 1;
  18. return func.apply(this, arguments);
  19. };
  20. }
  21.  
  22. function foo() { } /* カウントしたい関数 */
  23.  
  24. foo = callcounter(foo); /* fooをクロージャと差し替え */
  25.  
  26. for (var i = 0; i < 100; i++) {
  27. foo();
  28. }
  29.  
  30. console.log(count_hash.foo); // 100
  31.  
Success #stdin #stdout 0.06s 11184KB
stdin
Standard input is empty
stdout
100