Add toString to some of the objects


#1

Support toString() in more classes. During debugging it is frequently the case to check the values of an object in the console.

Use Case:
Yusuke is writing a plugin to add 3d transforms to the selected items. He edits code, saves it, reloads his plugin and then runs it. He opens the console and checks the values. For each bounds object he writes four lines of code. He ponders if some day he would only have to write one line.

log("x:" + bounds.x)
log("y:" + bounds.y)
log("width:" + bounds.width)
log("height:" + bounds.height)

Example:

log("Local center point:" + item.localCenterPoint); // outputs [object Object]

Expected (desired) outcome:

log("Local center point:" + item.localCenterPoint); // outputs {x: 10, y: 10}

Suggested candidates:

item.globalBounds
item.globalDrawBounds
item.localCenterPoint
item.boundsInParent
item.topLeftInParent

#2

Finally a request I can whole-heartedly agree on :wink: (and which I vote for).

Aside from that, I think this might be part of Dev Tools/Debugging support from the roadmap, since integration of the chrome dev tools would hopefully also mean being able to “expand” a node object to see all its properties (the way the chrome console handles objects).


#3

As @pklaschka mentioned above, more dev tools support is coming soon. Hopefully, this will address your request here. Please stay tuned!


#4

If you use comma to pass values as a separate argument to console.log(), it will give you much nicer output for these simple object types that are not classes and don’t have a defined toString():

// "Local center point: [object Object]"
console.log("Local center point: " + item.localCenterPoint);

// "Local center point: { x: 10, y: 10 }"
console.log("Local center point:", item.localCenterPoint);

This is a great trick that works when logging from JS code in a browser too btw!