Created
October 31, 2011 14:02
-
-
Save engleek/1327553 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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