Skip to content

Instantly share code, notes, and snippets.

@watilde
Last active December 18, 2015 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save watilde/5822742 to your computer and use it in GitHub Desktop.
Save watilde/5822742 to your computer and use it in GitHub Desktop.
if(!Object.create) {
Object.create = function (o, prop) {
'use strict';
var keys = Object.keys(prop);
o['__propertiesObject__'] = o['__propertiesObject__'] || {};
keys.map(function(key) {
if (key in o) {
if (o['__propertiesObject__']['virtual'] !== true) {
throw new TypeError("Cannot overide property '"+ key +"' of #<Object>'");
}
}
o['__propertiesObject__'][key] = {
'writable': prop[key]['writable'] || false,
'configurable': prop[key]['configurable'] || false,
'enumerable': prop[key]['enumerable'] || false,
'virtual': prop[key]['writable'] || false
};
o[key] = prop[key]['value'];
});
return o;
};
}
// e.g
(function (global) {
'use strict';
var modName = 'foo';
var globalMod = global[modName] || {};
var mod = Object.create(globalMod, {
newOne: {
writable: false,
configurable: false,
enumerable: true,
value: function () {return 'Hello World!'; }
}
});
global[modName] = mod;
}(this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment