diff --git a/src/item/Item.js b/src/item/Item.js index b1cca192..dd81967c 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -1589,7 +1589,11 @@ var Item = this.Item = Base.extend(/** @lends Item# */{ }, */ - // TODO: toString + toString: function() { + return (this.constructor._name || 'Item') + (this._name + ? " '" + this._name + "'" + : ' @' + this._id); + }, statics: { drawSelectedBounds: function(bounds, ctx, matrix) { diff --git a/src/load.js b/src/load.js index c4dcbcb9..5e64759a 100644 --- a/src/load.js +++ b/src/load.js @@ -129,3 +129,12 @@ for (var i = 0; i < sources.length; i++) { + sources[i] + '">'); } +// Append a bit of code that names our classes. +// See src/paper.js for an in-depth explanation. +document.write(''); + diff --git a/src/paper.js b/src/paper.js index 08d95656..60994a56 100644 --- a/src/paper.js +++ b/src/paper.js @@ -122,6 +122,15 @@ var paper = new function() { //#include "core/PaperScript.js" +// Iterate over all proced Base classes and set the _name property of their +// constructors to the key under which they are stored. This is a simple hack +// that allow us to use their names. +// Setting Function#name is not possible, as that is read-only. +Base.each(this, function(val, key) { + if (val && val.prototype instanceof Base) + val._name = key; +}); + // Finally inject the classes set on 'this' into the PaperScope class and create // the first PaperScope and return it, all in one statement. return new (PaperScope.inject(this));