• SimplePropertyRetriever


    var SimplePropertyRetriever = {
        getOwnEnumerables: function (obj) {
            return this._getPropertyNames(obj, truefalsethis._enumerable); // Or could use for..in filtered with hasOwnProperty or just this: return Object.keys(obj);
        },
        getOwnNonenumerables: function (obj) {
            return this._getPropertyNames(obj, truefalsethis._notEnumerable);
        },
        getOwnEnumerablesAndNonenumerables: function (obj) {
            return this._getPropertyNames(obj, truefalsethis._enumerableAndNotEnumerable); // Or just use: return Object.getOwnPropertyNames(obj);
        },
        getPrototypeEnumerables: function (obj) {
            return this._getPropertyNames(obj, falsetruethis._enumerable);
        },
        getPrototypeNonenumerables: function (obj) {
            return this._getPropertyNames(obj, falsetruethis._notEnumerable);
        },
        getPrototypeEnumerablesAndNonenumerables: function (obj) {
            return this._getPropertyNames(obj, falsetruethis._enumerableAndNotEnumerable);
        },
        getOwnAndPrototypeEnumerables: function (obj) {
            return this._getPropertyNames(obj, truetruethis._enumerable); // Or could use unfiltered for..in
        },
        getOwnAndPrototypeNonenumerables: function (obj) {
            return this._getPropertyNames(obj, truetruethis._notEnumerable);
        },
        getOwnAndPrototypeEnumerablesAndNonenumerables: function (obj) {
            return this._getPropertyNames(obj, truetruethis._enumerableAndNotEnumerable);
        },
        // Private static property checker callbacks
        _enumerable : function (obj, prop) {
            return obj.propertyIsEnumerable(prop);
        },
        _notEnumerable : function (obj, prop) {
            return !obj.propertyIsEnumerable(prop);
        },
        _enumerableAndNotEnumerable : function (obj, prop) {
            return true;
        },
        // Inspired by http://stackoverflow.com/a/8024294/271577
        _getPropertyNames : function getAllPropertyNames(obj, iterateSelfBool, iteratePrototypeBool, includePropCb) {
            var props = [];

            do {
                if (iterateSelfBool) {
                    Object.getOwnPropertyNames(obj).forEach(function (prop) {
                        if (props.indexOf(prop) === -1 && includePropCb(obj, prop)) {
                            props.push(prop);
                        }
                    });
                }
                if (!iteratePrototypeBool) {
                    break;
                }
                iterateSelfBool = true;
            } while (obj = Object.getPrototypeOf(obj));

            return props;
        }
    };
  • 相关阅读:
    Charles使用
    将当前项目加入系统变量中
    JVM之gc相关
    jdk安装
    nginx相关
    oracle带输入输出参数存储过程(包括sql分页功能)
    ajax 全局拦载处理,可加密、过滤、筛选、sql防注入处理
    01.Java关键字,常量,变量,数值类型
    01.Java数据结构和多线程
    02.MySQL.存储引擎-事务-隔离级别-锁
  • 原文地址:https://www.cnblogs.com/shidengyun/p/5420892.html
Copyright © 2020-2023  润新知