mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
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().
This commit is contained in:
parent
3bd6122e82
commit
de87c1f97a
3 changed files with 23 additions and 1 deletions
|
@ -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) {
|
||||
|
|
|
@ -129,3 +129,12 @@ for (var i = 0; i < sources.length; i++) {
|
|||
+ sources[i] + '"></script>');
|
||||
}
|
||||
|
||||
// Append a bit of code that names our classes.
|
||||
// See src/paper.js for an in-depth explanation.
|
||||
document.write('<script type="text/javascript">\
|
||||
Base.each(this, function(val, key) {\
|
||||
if (val && val.prototype instanceof Base)\
|
||||
val._name = key;\
|
||||
});\
|
||||
</script>');
|
||||
|
||||
|
|
|
@ -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));
|
||||
|
|
Loading…
Reference in a new issue