Ai
2 Star 0 Fork 0

mirrors_WebReflection/interface

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
interface.js 2.01 KB
一键复制 编辑 原始数据 按行查看 历史
Andrea Giammarchi 提交于 2017-06-20 17:05 +08:00 . simplified interface
/*! Copyright (c) 2017, Andrea Giammarchi, @WebReflection */
(function (F, O, R) {'use strict';
if ('implements' in F) return;
var
dPs = O.defineProperties,
gOPDs = O.getOwnPropertyDescriptors,
ownKeys = R.ownKeys
;
function Interface() {}
Interface.prototype = O.create(null);
function augmentFunction(target, implementable) {
var descriptors = gOPDs(implementable);
if (typeof implementable === 'function') {
delete descriptors.prototype;
dPs(target, descriptors);
dPs(target.prototype, gOPDs(implementable.prototype));
} else {
augmentObject(target.prototype, implementable, descriptors);
}
}
function augmentObject(target, implementable) {
if (implementable instanceof Interface) {
dPs(target, gOPDs(implementable));
} else {
for (var
descriptors = gOPDs(implementable),
keys = ownKeys(descriptors),
i = 0, length = keys.length; i < length; i++
) {
descriptors[keys[i]].enumerable = false;
}
dPs(target, descriptors);
}
}
O.defineProperty(
F, 'implements',
{
configurable: true,
value: function () {
for (var
isObject = this === O,
target = isObject ? {} : class extends this {},
descriptors = isObject ? target : target.prototype,
i = 0, l = arguments.length; i < l; i++
) {
dPs(descriptors, gOPDs(arguments[i]));
}
return target;
}
}
);
O.defineProperty(
F, 'interface',
{
configurable: true,
value: function () {
for (var
isClass = typeof arguments[arguments.length - 1] === 'function',
iFace = isClass ? class extends Interface {} : new Interface,
augment = isClass ? augmentFunction : augmentObject,
i = 0, length = arguments.length; i < length; i++
) {
augment(iFace, arguments[i]);
}
return iFace;
}
}
);
}(Function.prototype, Object, Reflect));
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors_WebReflection/interface.git
git@gitee.com:mirrors_WebReflection/interface.git
mirrors_WebReflection
interface
interface
master

搜索帮助