Console - count

by Julien Roche

HTML

<h1>Open your Dev console</h1>

Babel + JSX

function count(target, key, descriptor) {
  const myMethod = descriptor.value;
  descriptor.value = function (...arg) {
    console.count(myMethod.name);
    return myMethod.apply(this, arg);
  };
	return descriptor;
}

class MyClass {
  @count
  myAwesomeFunction() {
    const randomColor = Math.floor(Math.random()*16777215).toString(16);
    console.info('%cNo really awesome...', `color:#${randomColor};`);
  }	
}

const instance = new MyClass();
const howManyTime = Math.ceil(Math.random() * 10);
console.info('We should call the method %s times', howManyTime);

for (let i = 0; i < howManyTime; ++i) {
	instance.myAwesomeFunction();
}