jh-common-dataaccess
Version:
common-dataaccess
38 lines (37 loc) • 685 B
JavaScript
module.exports = class EmtityClass {
/**
* 构造器(object属性键值对、array属性列表)
*/
constructor() {
const _keys = [];
if (arguments[1] instanceof Array) {
_keys.push(...arguments[1]);
}
Object.defineProperty(this, '_keys', {
configurable: false,
writable: false,
enumerable: false,
value: _keys,
});
this.set(arguments[0]);
}
/**
* 获取属性
* @param {*} key
*/
get(key) {
return this[key];
}
/**
* 设置属性
*/
set() {
if (arguments[0] instanceof Object) {
Object.keys(arguments[0]).forEach(key => {
if ((this._keys || []).includes(key)) {
this[key] = arguments[0][key];
}
});
}
}
};