WenTao-Love / base2

Automatically exported from code.google.com/p/base2
0 stars 1 forks source link

base2.Package.addName doesn't provide toString methods #112

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago

Hi,

Only classes declared during package creation have a toString method.
However classes added afterwards using Package.addName() don't get this method.
This is a pity as not everybody uses your build system to create package
files from separate source files, and addName is very useful when you have
your classes in several files.

I fixed it locally by subclassing base2.Package, overriding the addName
method, and copying your code from the Package constructor, but I guess it
would be better to support it directly in the original method.

As this is the only way to I know obtain the fully qualified name of a
class from this class / an instance of it, I think it would really help.

You surely don't need it, but here's what I did anyway:

  addName: function ( name, value ) {
    if ( !this[name] ) {
      this.base( name, value );
      var packageName = String2.slice( this, 1, -1);
      if ( this[name] && this[name].ancestorOf == Base.ancestorOf &&
!this[name].toString ) {    // it's a class
        this[name].toString = Function2.K("[" + packageName + "." + name +
"]");
      }
    }
  }

esc0-

Original issue reported on code.google.com by mesco...@gmail.com on 12 Jun 2009 at 9:10

GoogleCodeExporter commented 9 years ago
OK, I'll add this. Your code is pretty close to mine too. ;)

Original comment by dean.edw...@gmail.com on 21 Jun 2009 at 3:51