JSFiddle - React, Tailwind, and code Playground

by darcyclarke

JavaScript

// Getters / Setters
// http://ejohn.org/blog/javascript-getters-and-setters/
function obj( val ) {
    var value = val;
    this.get = function() {
        return value;  
    };
    this.set = function( val ) {
        value = val;  
    };
    return this;
};

// use
var foo = new obj( 'bar' );

// wat?
console.dir( foo );

// encapsulation... which is a good thing 
console.log( foo.value );

// getter
console.log( foo.get() );

// setter
foo.set( 'baz' );
console.log( foo.get() );