mikeswartz / javascript-quick-reference

Some common use JavaScript for quick reference.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

javascript-quick-reference

Some common use JavaScript for quick reference.

Init closure function

var outputDiv = document.getElementById('output');

var init = (function(val1) {
  outputDiv.innerHTML = val1;
  return {
    getFoo: function() {
      return outputDiv.innerHTML;
    },
    setFoo: function(val2) {
      outputDiv.innerHTML = val2;
    }
  }

})('first set this');

init.setFoo('replace it with this awesomeness');
<div id="output">
  replace this
</div>

About

Some common use JavaScript for quick reference.