Skip to content

Instantly share code, notes, and snippets.

@qpwo
Last active March 11, 2018 22:13
Show Gist options
  • Select an option

  • Save qpwo/94dc8278f38d3447cc6d8dc2e7a2d197 to your computer and use it in GitHub Desktop.

Select an option

Save qpwo/94dc8278f38d3447cc6d8dc2e7a2d197 to your computer and use it in GitHub Desktop.
A minimal possible working example of a javascript library
var lukemath = new (function() {
var privatePi = 3.14;
this.tau = 2 * privatePi;
var privateSquare = function(n) {
return n * n;
}
this.fourth = function(n) {
return privateSquare(privateSquare(n));
}
})();
// > lukemath.tau
// 6.28
// > lukemath.fourth
// [Function]
// > lukemath.fourth(5)
// 625
// > lukemath.privatePi
// undefined
// > lukemath.privateSquare
// undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment