简化工具函数

This commit is contained in:
zhw2590582 committed 2019-11-22 20:50:14 +08:00
1 parent be4d1d0437
commit 1270167a3e
26 files changed
+182 -152

No files matched your search

+3 -3
View File
@@ -1,5 +1,5 @@
import { hasClass, addClass, removeClass, append, setStyle, setStyles, tooltip } from './dom';
import { hasOwnProperty, defineProperty } from './property';
import { has, def } from './property';
import { errorHandle } from './error';
export default class Component {
@@ -35,7 +35,7 @@ export default class Component {
if (!this.$parent || option.disable) return {};
this.id += 1;
const name = option.name || `${this.name}${this.id}`;
errorHandle(!hasOwnProperty(this, name), `Cannot add a component that already has the same name: ${name}`);
errorHandle(!has(this, name), `Cannot add a component that already has the same name: ${name}`);
const $ref = document.createElement('div');
$ref.classList.value = `art-${this.name} art-${this.name}-${name}`;
@@ -75,7 +75,7 @@ export default class Component {
callback($ref, this, this.art);
}
defineProperty(this, name, {
def(this, name, {
value: {
get $ref() {
return $ref;
+5 -8
View File
@@ -1,19 +1,16 @@
import { errorHandle } from './error';
const has = Object.prototype.hasOwnProperty;
export function hasOwnProperty(obj, name) {
return has.call(obj, name);
}
export const def = Object.defineProperty;
const def = Object.defineProperty;
export function defineProperty(obj, key, prop) {
return def(obj, key, prop);
const { hasOwnProperty } = Object.prototype;
export function has(obj, name) {
return hasOwnProperty.call(obj, name);
}
export function proxyPropertys(target, ...sources) {
return sources.reduce((result, source) => {
Object.getOwnPropertyNames(source).forEach(key => {
errorHandle(!hasOwnProperty(result, key), `Target attribute name is duplicated: ${key}`);
errorHandle(!has(result, key), `Target attribute name is duplicated: ${key}`);
def(result, key, Object.getOwnPropertyDescriptor(source, key));
});
return result;