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;
        }
    };
  • 相关阅读:
    ASP.NET MVC中你必须知道的13个扩展点
    ASP.NET MVC扩展库
    AutoFac简介
    中小型研发团队架构实践十:应用监控怎么做?
    IDEA+Mybatis-generator代码生成工具
    IDEA+EasyCode实现代码生成
    myeclipse中导入的js文件报错(出现红叉叉,提示语法错误)
    Ibatis中常见错误解决方案
    注解
    structs常见错误
  • 原文地址:https://www.cnblogs.com/shidengyun/p/5420892.html
Copyright © 2011-2022 走看看