åæå¯è½ããããã£ã¯ãå é¨ã®åæå¯è½ï¼enumerableï¼ãã©ã°ã true ã«è¨å®ããã¦ããããããã£ã§ããããã¯ãåç´ãªä»£å ¥ãåæåã§ä½æãããããããã£ã®ããã©ã«ãã§ã (Object.defineProperty ã§è¿½å ããããããã£ã¯ããã©ã«ãã§åæå¯è½æ§ã false ã«ãªãã¾ãï¼ãããããã£ã®ãã¼ã Symbol ã§ãªãéããåæå¯è½ãªããããã£ã¯ for...in ã«ã¼ãã«ã®å¯¾è±¡ã«ãªãã¾ããããããã£ã®æææ¨©ã¯ãããããã£ããããã¿ã¤ããã§ã¼ã³ã§ã¯ãªãããªãã¸ã§ã¯ãã«ç´æ¥å±ãã¦ãããã©ããã«ãã£ã¦æ±ºã¾ãã¾ãããªãã¸ã§ã¯ãã®ããããã£ã¯ã¾ã¨ãã¦åãæ±ããã¨ãã§ããããããã£ãæ¤åºãå復ãåæãåå¾ããããã®å¤ãã®çµã¿è¾¼ã¿æ©è½ãããã¾ãã以ä¸ã«ã使ç¨å¯è½ãªãã£ã¼ãã¨ä¸è¶³ãã¦ããã«ãã´ãªãåå¾ããæ¹æ³ã示ããµã³ãã«ã³ã¼ãã示ãã¾ãã
åæå¯è½æ§/æææ¨©ã«ããããããã£ã®åå¾ä»¥ä¸ã«ç¤ºãã®ã¯å ¨ã¦ã®ã±ã¼ã¹ã§æãå¹ççãªã¢ã«ã´ãªãºã ã§ã¯ãªããç°¡æ½ãªãã¢ã§ãããã¨ã«æ³¨æãã¦ãã ããã
SimplePropertyRetriever.使ããã get ã¡ã½ãã(obj).indexOf(prop) > -1
SimplePropertyRetriever.使ããã get ã¡ã½ãã(obj).forEach(function (value, prop) {});
(ã¾ã㯠filter()
, map()
ãªã©ã使ã)var SimplePropertyRetriever = {
getOwnEnumerables: function (obj) {
return this._getPropertyNames(obj, true, false, this._enumerable);
// Or could use for..in filtered with hasOwnProperty or just this: return Object.keys(obj);
},
getOwnNonenumerables: function (obj) {
return this._getPropertyNames(obj, true, false, this._notEnumerable);
},
getOwnEnumerablesAndNonenumerables: function (obj) {
return this._getPropertyNames(
obj,
true,
false,
this._enumerableAndNotEnumerable,
);
// Or just use: return Object.getOwnPropertyNames(obj);
},
getPrototypeEnumerables: function (obj) {
return this._getPropertyNames(obj, false, true, this._enumerable);
},
getPrototypeNonenumerables: function (obj) {
return this._getPropertyNames(obj, false, true, this._notEnumerable);
},
getPrototypeEnumerablesAndNonenumerables: function (obj) {
return this._getPropertyNames(
obj,
false,
true,
this._enumerableAndNotEnumerable,
);
},
getOwnAndPrototypeEnumerables: function (obj) {
return this._getPropertyNames(obj, true, true, this._enumerable);
// Or could use unfiltered for..in
},
getOwnAndPrototypeNonenumerables: function (obj) {
return this._getPropertyNames(obj, true, true, this._notEnumerable);
},
getOwnAndPrototypeEnumerablesAndNonenumerables: function (obj) {
return this._getPropertyNames(
obj,
true,
true,
this._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;
},
};
æ¤åºãã¼ãã« in
for..in
obj.hasOwnProperty
obj.propertyIsEnumerable
Object.keys
Object.getOwnPropertyNames
Object.getOwnPropertyDescriptors
Reflect.ownKeys()
åæå¯è½ true true true true true true true true åæä¸å¯è½ true false true false false true true true Symbols ãã¼ true false true true false false true true ç¶æ¿ãããåæå¯è½ true true false false false false false false ç¶æ¿ãããåæä¸å¯è½ true false false false false false false false ç¶æ¿ããã Symbols ãã¼ true false false false false false false false é¢é£æ
å ±
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4