about having something similar to the extend attribute ?

zwetan zwetan at gmail.com
Sat Jan 6 11:56:43 PST 2007


as seen here
http://www.mozilla.org/js/language/js20/rationale/miscellaneous.html

Class Extensions / extend Attribute

"namespace StringExtension;

StringExtension extend(String) function scramble():String {...}
StringExtension extend(String) function unscramble():String {...}

use namespace(StringExtension);

var x:String = "abc".scramble();"

would it be as much complicated to use namespace shadowing
http://developer.mozilla.org/es4/proposals/namespace_shadowing.html
to obtain the same kind of behaviour, simply put "add methods to a
class defined somewhere else" ?

for ex:

package
{
	public final class String extends Object
	{
        ...
        }
}

being able to define an extension like this

package
{
        public namespace StringExtension;

	StringExtension class String extends Object
	{
        ...
        public function scramble():String {...}
        public function unscramble():String {...}
        ...
        }
}


and then use it in strict mode

use namespace StringExtension;
var foobar:String = "abcdef".scramble();


for now the only option to do that is to be in standard mode
and add to the prototype, this is good
but as a dev what I really want is the strict mode
but still being able to extend such final class
(even if that idea may raise some hairs in horror ;))

zwetan



More information about the Es4-discuss mailing list