Last active
December 18, 2015 17:59
-
-
Save watilde/5822742 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
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