Files
polymer/components/perf-lib/polymer/util.html
2014-11-17 10:38:22 -08:00

36 lines
1.1 KiB
HTML

<script>
// a tiny bit of sugar for `document.currentScript.ownerDocument`
// sadly `import` is reserved, so we need another name or
// you have to refer to this value `window.import`
Object.defineProperty(window, 'import', {
enumerable: true,
configurable: true,
get: function() {
var script = document._currentScript || document.currentScript;
return script.ownerDocument;
}
});
// copy own properties from 'api' to 'prototype, with name hinting for 'super'
function extend(prototype, api) {
if (prototype && api) {
// use only own properties of 'api'
Object.getOwnPropertyNames(api).forEach(function(n) {
// acquire property descriptor
var pd = Object.getOwnPropertyDescriptor(api, n);
if (pd) {
// clone property via descriptor
Object.defineProperty(prototype, n, pd);
// cache name-of-method for 'super' engine
if (typeof pd.value == 'function') {
// hint the 'super' engine
pd.value.nom = n;
}
}
});
}
return prototype;
};
</script>