JSFiddle - React, Tailwind, and code Playground

by Nico Po

Babel + JSX

class myCtrl {
  constructor ( $log ) {
    'ngInject';

    // Dependency Injections
    var privateLog  = $log;      // Private but scoped to constructor
    this.publicLog  = $log;      // Public

    // Default attributes
    this.foo = 'bar';

    this.publicLog.log('it works in constructor');  // logs 'it works in constructor'
    privateLog.log('it works in constructor'); 			// logs 'it works in constructor'
  }

  logSomething () {
    this.publicLog.log('it works in class method'); // logs 'it works in class method'
    try {
    	privateLog.log('it works in class method'); 		// ReferenceError
    }
    catch(e) {
    	console.log(e);
    }
  }
}

var test = new myCtrl(console);

test.logSomething();
test.publicLog.log('is public');      // logs 'is public'
try {
  test.privateLog.log('is private');
}
catch(e) {
  console.log(e);										  // TypeError
}