function init() { function ownKeys(object) { return isObjectLike(object) ? Reflect.ownKeys(object) : [] } return ownKeys }
return [] let names = Reflect.ownKeys(instance) names = names.filter((name) => {
const mimicFn = (to, from) => { for (const prop of Reflect.ownKeys(from)) { Object.defineProperty(to, prop, Object.getOwnPropertyDescriptor(from, prop)); } return to; }
addRules (rules = {}) { if (typeof rules === 'function') { rules = rules(this) } Reflect.ownKeys(rules).forEach(interfaceName => this.addRule(interfaceName, rules[interfaceName], false)) this.rulesDetectLazyLoad() }
export function EasyComputedStyle(computed, base = Object.create(null)) { return new Proxy(base, { ownKeys(target) { return Reflect.ownKeys(styleProperties); }, has(target, key) { return has(styleProperties, key); }, get(target, key) { if (!has(styleProperties, key)) throw new Error(`Failed to get a style property: '${key}' is not a valid style property name.`); return computed.get(key); } }); }
getAllMethods() { const methods = Reflect.ownKeys(this.client) .filter(p => typeof this.client[p] === 'function' && !p.endsWith('Async')); return methods; }
const keys = Reflect.ownKeys(proto) .filter(key => typeof key !== 'symbol' && !key.startsWith('_') &&
/** * 获取一个实例的所有方法 * @param obj 对象实例 * @param option 参数 * * ```js * let validateFuncKeys: string[] = getAllMethodNames(this, { * filter: key => * /validate([A-Z])\w+/g.test(key) && typeof this[key] === "function" * }); * ``` */ const getAllMethodNames = (obj, option) => { let methods = new Set(); // tslint:disable-next-line:no-conditional-assignment while ((obj = Reflect.getPrototypeOf(obj))) { let keys = Reflect.ownKeys(obj); keys.forEach(k => methods.add(k)); } let keys = Array.from(methods.values()); return prefixAndFilter(keys, option); }
/** * Helper that recursively merges two data objects together. */ function mergeData (to, from) { if (!from) { return to } var key, toVal, fromVal; var keys = hasSymbol ? Reflect.ownKeys(from) : Object.keys(from); for (var i = 0; i < keys.length; i++) { key = keys[i]; // in case the object is already observed... if (key === '__ob__') { continue } toVal = to[key]; fromVal = from[key]; if (!hasOwn(to, key)) { set(to, key, fromVal); } else if ( toVal !== fromVal && isPlainObject(toVal) && isPlainObject(fromVal) ) { mergeData(toVal, fromVal); } } return to }
Reflect.ownKeys (proto).forEach ( function (name) { if (name !== 'constructor') { if (hasMethod (proto, name)) { array.push (name); } } } );
function resolveInject (inject, vm) { if (inject) { // inject is :any because flow is not smart enough to figure out cached // isArray here var isArray = Array.isArray(inject); var result = Object.create(null); var keys = isArray ? inject : hasSymbol ? Reflect.ownKeys(inject) : Object.keys(inject); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var provideKey = isArray ? key : inject[key]; var source = vm; while (source) { if (source._provided && provideKey in source._provided) { result[key] = source._provided[provideKey]; break } source = source.$parent; } } return result } }
/** * 获得实例的所有字段名 * @param obj 实例 * @param option 参数项 * * ```js * let keys = getAllFieldNames(this, { * filter: key => { * const value = this[key]; * if (isArray(value)) { * if (value.length === 0) { * return false; * } * for (const it of value) { * if (!(it instanceof Rule)) { * throw new Error("every item must be a instance of Rule"); * } * } * return true; * } else { * return value instanceof Rule; * } * } * }); * ``` */ function getAllFieldNames(obj, option) { let keys = Reflect.ownKeys(obj); return prefixAndFilter(keys, option); }
Reflect.ownKeys(rules).forEach(function (interfaceName) { return _this4.addRule(interfaceName, rules[interfaceName], false); });
function findMembers(instance, fieldPrefix, funcPrefix) { // 递归函数 function _find(instance) { //基线条件(跳出递归) if (instance.__proto__ === null) return [] let names = Reflect.ownKeys(instance) names = names.filter((name)=>{ // 过滤掉不满足条件的属性或方法名 return _shouldKeep(name) }) return [...names, ..._find(instance.__proto__)] } function _shouldKeep(value) { if (value.startsWith(fieldPrefix) || value.startsWith(funcPrefix)) return true } return _find(instance) }
Reflect.ownKeys(rules).forEach(function (interfaceName) { return _this4.addRule(interfaceName, rules[interfaceName], false); });