wrap

Wrap a thing with a Type to filter out properties, while preserving the Id. A wrapped thing inherits the methods from the type it is wrapped with.

For a more advanced example using wrap() and unwrap() see <Type>.

Function

thing.wrap([Type])

Arguments

Argument Arguments Description
Type str/anonymous (optional) Type’s name or anonumous type to wrap the thing with. If not given, the thing will be wrapped with its own type.

Return value

A wrapped thing.

Example

This code shows an example using wrap():

// Create a Type to return just an email field.
set_type('_Email', {email: 'str'}, true, true);

user = {
    name: 'Jeroen van der Heijden',
    email: 'jeroen@cesbit.com',
    gender: 'male',
};

// Return the email field
user.wrap('_Email');

Return value in JSON format

{
    "email": "jeroen@cesbit.com"
}

Same example using an anonymous type:

user = {
    name: 'Jeroen van der Heijden',
    email: 'jeroen@cesbit.com',
    gender: 'male',
};

// Return the email field
user.wrap(&{email: 'str'});

Return value in JSON format

{
    "email": "jeroen@cesbit.com"
}