zoukankan      html  css  js  c++  java
  • 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;
        }
    };
  • 相关阅读:
    【kd-tree】bzoj2648 SJY摆棋子
    【kd-tree】bzoj3053 The Closest M Points
    【堆】【kd-tree】bzoj2626 JZPFAR
    【kd-tree】bzoj1941 [Sdoi2010]Hide and Seek
    【kd-tree】bzoj2850 巧克力王国
    【kd-tree】bzoj3489 A simple rmq problem
    【kd-tree】bzoj4066 简单题
    【二维莫队】【二维分块】bzoj2639 矩形计算
    【kd-tree】bzoj1176 [Balkan2007]Mokia
    【kd-tree】bzoj3290 Theresa与数据结构
  • 原文地址:https://www.cnblogs.com/shidengyun/p/5420892.html
Copyright © 2011-2022 走看看