PP.ensureObject

Syntax

ensureObject(type: PP.Object, obj: Object);

Parameters

type. Object type:

obj. JSON object to convert, or an object of specified type.

Description

The ensureObject method converts a specified JSON object to object with specified type.

Comments

This method returns a PP object with specified type.

Example

To execute the example, add a link to PP.js scenario file to HTML page. Create three points and show their coordinates in the browser console:

// Create a point with the coordinates (1, 1)
var point = PP.ensureObject(PP.Point, {
    X: 1,
    Y: 1
});
// Create an array of points with the coordinates (2, 2) and (3, 3)
var points = PP.ensureObjectArray(PP.Point, [{
        X: 2,
        Y: 2
    }, {
        X: 3,
        Y: 3
    }
]);
// Add the first point this array
points.push(point);
// Output coordinates of the created points
for (var i in points) {
    console.log("Point coordinates" + i + ": (" + points[i].getX() + ", " + points[i].getY() + ")");
};

After executing the example three points are created and their coordinates are displayed to the browser console:

Coordinates of the point 0: (2, 2)
Coordinates of the point 1: (3, 3)
Coordinates of the point 2: (1, 1)

See also:

PP