From de87c1f97af44b109910f625ef63c154a35b1f3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Thu, 7 Jul 2011 22:14:09 +0200 Subject: [PATCH] Define a bit of code that names all our class constructors based on the property name under which they were stored, and use that in Item#toString(). --- src/item/Item.js | 6 +++++- src/load.js | 9 +++++++++ src/paper.js | 9 +++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) 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));