JSFiddle - React, Tailwind, and code Playground

by Nick Karnik

JavaScript 1.7

class Test {
  _temp1() {
    console.log('in temp 1')
  }

  _temp2() {
    console.log('in temp 2')
  }
}

function makeFluent(fn, opts) {
  /* console.log(fn, opts) */
  fn()
  return "this"
}

function wrapFn(fn) {
  return function(options) {
    /* console.log('inside inner function...calling make fluent') */
    return makeFluent(fn, options)
  }
}

let res = Object.getOwnPropertyNames(Test.prototype).filter(a => a.indexOf('_') === 0)
res.forEach(item => {
  let fn = Test.prototype[item]
  let wrappedFn = wrapFn(fn)
  Test.prototype[item.replace('_', '')] = wrappedFn
})

console.log(Test.prototype.temp1)
let a = new Test()
let val = a.temp1('this is a param')
console.log(val)