getter / setter

by yshrkn

TypeScript

function test(param) {
  var _text = "Huh!?";

  return {
    get text() { 
      return "text is " + _text;
    },
    set text(param) {
    	if (param === "NG") {
      	console.log("You cant not set word 'NG'.");
        return;
      } 
      _text = param;
    },
  };
}

var a = test();

console.log(a.text);

a.text = "NG";

console.log(a.text);