can-symbol
Version:
Well known symbols used to detail how to operate on different objects
35 lines (25 loc) • 1.32 kB
Markdown
String)} can-symbol/symbols/getOwnKeyDescriptor can.getOwnKeyDescriptor
can-symbol/symbols/shape
Describe the attributes of an object's keyed property.
`@ .getOwnKeyDescriptor(key)`
Return a single key's descriptor from the object, as defined by the custom behavior of this function.
```
var shapeless = {};
// Nothing enumerable in a shapeless object
shapeless[canSymbol.for('can.getOwnKeyDescriptor')] = function() { return; }
// Banana is on the prototype chain, so default "own key descriptor" functions would not return it.
var thingsInMyEar = Object.create(
"banana": {
peeled: false
}
});
thingsInMyEar[canSymbol.for('can.getOwnKeyDescriptor')] = function(key) {
if(Object.getOwnPropertyNames(this).indexOf(key) || key === "banana") {
return !!Object.getOwnPropertyDescriptor(this, key) ||
this[canSysmbol.for('can.getOwnKeyDescritpor')].call(this[canSymbol.for('proto')], key);
}; // There's always a banana in my ear
};
```
{Object} an object with named properties
{String} key The string key to look up on the object
{Object} a property descriptor, containing the keys `configurable`, `enumerable`, and either `value` and `writable`, or `get` and `set`, if the property exists on the object; `undefined` otherwise.
{function(