Skip to content

Instantly share code, notes, and snippets.

@donburks donburks/mkobj-example.js Secret
Last active Aug 29, 2015

Embed
What would you like to do?
Object Constructor Library
mkobj.register('snuggles', 100);
mkobj.register('getSnuggles', function() { return this.snuggles; });
mkobj.register('setSnuggles', function(snugs) { this.snuggles = snugs; });
mkobj.register('saySnuggles', function() { console.log("There are " + this.snuggles + " snuggles!");});
var snuggleObj = mkobj.construct('snuggles', 'getSnuggles', 'saySnuggles');
snuggleObj.saySnuggles();
var mkobj = {
construct: function() {
var obj = {},
temp, prop,
i = arguments.length;
while(i--) {
temp = arguments[i];
if (mkobj.registered[temp]) {
obj[temp] = mkobj.registered[temp];
}
}
return obj;
},
registered: {},
register: function(key, cb) {
if (cb === null && mkobj.registered[key]) {
delete mkobj.registered[key];
} else {
mkobj.registered[key] = cb;
}
}
};
var mkobj={construct:function(){for(var b={},a,c=arguments.length;c--;)a=arguments[c],objlib.registered[a]&&(b[a]=objlib.registered[a]);return b},registered:{},register:function(b,a){null===a&&objlib.registered[b]?delete objlib.registered[b]:objlib.registered[b]=a}};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.