2014-04-02 06:25:51 -04:00
|
|
|
/**
|
|
|
|
* @fileOverview inherit, an alternative for __proto__
|
|
|
|
* @author YUKI "Piro" Hiroshi
|
2014-04-04 14:15:24 -04:00
|
|
|
* @contributor Infocatcher
|
2016-09-07 02:53:01 -04:00
|
|
|
* @version 4
|
2014-04-02 06:25:51 -04:00
|
|
|
*
|
|
|
|
* @license
|
2016-09-07 02:53:01 -04:00
|
|
|
* The MIT License, Copyright (c) 2014-2016 YUKI "Piro" Hiroshi.
|
2014-04-02 06:25:51 -04:00
|
|
|
* https://github.com/piroor/fxaddonlib-inherit/blob/master/LICENSE
|
|
|
|
* @url http://github.com/piroor/fxaddonlib-inherit
|
|
|
|
*/
|
|
|
|
|
2015-10-10 23:40:17 -04:00
|
|
|
var EXPORTED_SYMBOLS = ['inherit'];
|
2014-04-02 06:25:51 -04:00
|
|
|
|
|
|
|
function toPropertyDescriptors(aProperties) {
|
|
|
|
var descriptors = {};
|
|
|
|
Object.keys(aProperties).forEach(function(aProperty) {
|
|
|
|
var description = Object.getOwnPropertyDescriptor(aProperties, aProperty);
|
|
|
|
descriptors[aProperty] = description;
|
|
|
|
});
|
|
|
|
return descriptors;
|
|
|
|
}
|
|
|
|
|
2016-09-07 02:53:01 -04:00
|
|
|
function inherit(aParent, aExtraProperties, aObjectClass) {
|
|
|
|
aObjectClass = aObjectClass || Object;
|
2014-04-02 06:25:51 -04:00
|
|
|
if (aExtraProperties)
|
2016-09-07 02:53:01 -04:00
|
|
|
return aObjectClass.create(aParent, toPropertyDescriptors(aExtraProperties));
|
2014-04-02 06:25:51 -04:00
|
|
|
else
|
2016-09-07 02:53:01 -04:00
|
|
|
return aObjectClass.create(aParent);
|
2014-04-02 06:25:51 -04:00
|
|
|
}
|
2016-09-07 02:53:01 -04:00
|
|
|
|