can-symbol
Version:
Well known symbols used to detail how to operate on different objects
32 lines (22 loc) • 889 B
Markdown
Boolean} can-symbol/symbols/getIdentity can.getIdentity
can-symbol/symbols/shape
Returns a name/label that identifies the object
`@ .getIdentity()`
The `@@@ .getIdentity` symbol points to a function/value that labels the
identity of the object. Ideally this should be a unique identifier, like the
primary key (id) in a database table. The `@@@ .getName` symbol behavior
uses the value of `@ .getIdentity` (if set) to decorate its output.
E.g:
```js
const obj = {};
import canReflect from "can-reflect";
// without setting `can.getIdentity`
canReflect.getName( obj ); // -> Object<>
foo[ canSymbol.for( "can.getIdentity" ) ] = function() {
return "15";
};
obj[ canSymbol.for( "can.getIdentity" ) ](); //-> "15"
canReflect.getName( obj ); // -> Object<15>
```
{String} The name/label that identifies the object
{