Skip to content

Instantly share code, notes, and snippets.

@clamstew
Created May 27, 2014 16:12
Show Gist options
  • Save clamstew/8191fbfb68070b720c28 to your computer and use it in GitHub Desktop.
Save clamstew/8191fbfb68070b720c28 to your computer and use it in GitHub Desktop.
A small maker nap constructor to ponder
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>My Title</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<!-- body goes here -->
<script type="text/javascript">
var Maker = function() {
var naps = 0;
nap = 6;
this.getNaps = function() {
return naps;
};
this.nap = function() {
naps += 1;
};
};
var maker1 = new Maker();
maker1.nap();
console.log("We're able to access the internal nap count", maker1.getNaps() == 1 );
console.log("And the private data is inaccessible to us.", Maker.naps === undefined );
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment