JSFiddle - React, Tailwind, and code Playground

by Julien Roche

HTML

<p></p>

Babel + JSX

const outElement = document.querySelector('p');

function log(message) {
	const element = document.createElement('div');
  element.textContent = element;
  outElement.appendChild(element);
}

function instrument(name) {
  return function decorator(t, n, descriptor) {
    const original = descriptor.value;
    if (typeof original === 'function') {
      descriptor.value = function(...args) {
        alert(`Arguments for ${name}: ${args}`);
        log(`Arguments for ${name}: ${args}`)
        
        try {
          const result = original.apply(this, args);
          return result;
        } catch (e) {
          throw e;
        }
      }
    }
    return descriptor;
  };
}


class Example {
  @instrument('aMarkerName')
  sum(a, b) {
    return a + b;
  }
}

const e = new Example();
e.sum(1, 2);