• 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;
        }
    };
  • 相关阅读:
    STL的适配器、仿函数学习之一:accumulate和for_each的使用心得
    百度笔试题--------数字拼接,求出最小的那个
    百度面试题----依概率生成
    百度笔试题----C语言版revert
    百度笔度题-----蚂蚁爬杆问题
    Try....Catch......Finally 的执行顺序
    数据库SQL SERVER 2008R2 远程连接配置说明
    C#中的数据库的连接方式分类说明(转载)
    网络通信—udp使用领悟
    (转载)C#网络通信之TCP连接
  • 原文地址:https://www.cnblogs.com/shidengyun/p/5420892.html
Copyright © 2020-2023  润新知