<p>Open developer console to see output</p>
class FooClass {
  constructor(available, secret) {
    this._secret = secret;
    this.available = available;
  }

  blab() {
    console.log(this._getUtterance());
  }

  _getUtterance() {
    return `My ${this._secret} thing is secret, my ${this.available} thing is not`;
  }
}

function FooConstructor(available, secret) {
  let _secret = secret;
  const _getUtterance = () => {
    return `My ${_secret} thing is secret, my ${this.available} thing is not`;
  };
  this.available = available;
  this.blab = () => {
    console.log(_getUtterance());
  };
}

function createFoo(available, secret) {
  let _secret = secret;
  function _getUtterance() {
    return `My ${_secret} thing is secret, my ${obj.available} thing is not`;
  }
  const obj = {
    available,
    blab() {
      console.log(_getUtterance());
    }
  };
  return obj;
}

const foo1 = new FooClass("public", "private");
const foo2 = new FooConstructor("public", "private");
const foo3 = createFoo("public", "private");

foo1.blab();
foo2.blab();
foo3.blab();

console.log(foo1.available, foo1._secret, foo1._getUtterance);
  // "public" "private" function _getUtterance()
console.log(foo2.available, foo2._secret, foo2._getUtterance);
  // "public" undefined undefined
console.log(foo3.available, foo3._secret, foo3._getUtterance);
  // "public" undefined undefined

console.log(foo1, foo2, foo3);

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.