Skip to content

Instantly share code, notes, and snippets.

@engleek
Created October 31, 2011 14:02
Show Gist options
  • Save engleek/1327553 to your computer and use it in GitHub Desktop.
Save engleek/1327553 to your computer and use it in GitHub Desktop.
(function (parent) {
/* Scope Private Variables */
var example_var = 'This var is private to the closure',
apple_count = 0; // Let's deal with counters too
/* Fruit Object */
var Fruit = parent.Fruit = {};
Fruit.name = 'Fruit';
Fruit.seal();
/* Apple Object : Extends Fruit Object */
var Apple = Object.create(Fruit, {
name: {
value: 'Apple'
}
});
Object.defineProperty(Apple, color, {
value: 'Red'
});
Object.defineProperty(Apple, number, {
get: function () {
return apple_count;
}
});
Apple.add = function (inc) {
apple_count += inc;
}
}) (window || export)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment