dirty Object.prototype and other javascript toolkits

2 views
Skip to first unread message

Sebastian Gurin

unread,
Jun 23, 2009, 9:00:26 PM6/23/09
to java2...@googlegroups.com
Hi all.

I'm successfully porting YUI http://developer.yahoo.com/yui/ widgets to java2script. I hope soon to have something working to publish. Nevertheless I step with the following problem..

I have accomplished to, with a relatively automatized "procedure", starting the porting of YAHOO.widget "classes" to java2script. However, when doing some testing with YAHOO.widget.Datatable (file:///home/sebastian/desarrollo/sgurin_workspace/yui/datatabletext.html) I encounter that YUI code fails if j2slib/j2slib.z was included in the html page.

I commented j2slib/java/lang/ClassExt.js code that "contaminates" Object.prototype and voila! the widget WORKED in conjunction with java2script without problems:

/*
* Invade the Object prototype!
* TODO: make sure that invading Object prototype does not affect other
* existed library, such as Dojo, YUI, Prototype, ...
*/
....
Object.getName = Clazz.innerFunctions.getName;

Object.prototype.equals = function (obj) {
return this == obj;
};
......


In this particular case, the fault was of Object.prototype.toString overriding:

Object.prototype.toString=function(){
if(this.__CLASS_NAME__!=null) {
return "["+this.__CLASS_NAME__+" object]";}else{return"[object]";
}
};

If I comment the last code, YUI datatable widget works fine with java2script!! :))).

Well, I'm not sure is this is a real bug, so I'm sending this mail to discuss it.

Hope I had explained myself correctly.


--
Sebastian Gurin <sgu...@softpoint.org>

Zhou Renjian

unread,
Jun 23, 2009, 9:30:31 PM6/23/09
to java2...@googlegroups.com
Comment below

On Wed, Jun 24, 2009 at 9:00 AM, Sebastian Gurin <sgu...@softpoint.org> wrote:

Hi all.

I'm successfully porting YUI http://developer.yahoo.com/yui/ widgets to java2script. I hope soon to have something working to publish. Nevertheless I step with the following problem..

I have accomplished to, with a relatively automatized "procedure", starting the porting of YAHOO.widget "classes" to java2script. However, when doing some testing with YAHOO.widget.Datatable (file:///home/sebastian/desarrollo/sgurin_workspace/yui/datatabletext.html) I encounter that YUI code fails if j2slib/j2slib.z was included in the html page.

I commented j2slib/java/lang/ClassExt.js code that "contaminates" Object.prototype and voila! the widget WORKED in conjunction with java2script without problems:

/*
 * Invade the Object prototype!
 * TODO: make sure that invading Object prototype does not affect other
 * existed library, such as Dojo, YUI, Prototype, ...
 */
....
Object.getName = Clazz.innerFunctions.getName;

Object.prototype.equals = function (obj) {
       return this == obj;
};
......




In this particular case, the fault was of  Object.prototype.toString overriding:

Object.prototype.toString=function(){
       if(this.__CLASS_NAME__!=null)   {
               return "["+this.__CLASS_NAME__+" object]";}else{return"[object]";
       }
};

It is a bug. Fixing like the bug may help:

Object.prototype.to$tring = Object.prototype.toString;
Object.prototype.toString = function () {
    if (this.__CLASS_NAME__! = null) {
        return "[" + this.__CLASS_NAME__ + " object]";
    } else {
        return this.to$tring ();
    }
};



If I comment the last code, YUI datatable widget works fine with java2script!! :))).

Well, I'm not sure is this is a real bug, so I'm sending this mail to discuss it.

Hope I had explained myself correctly.


--
Sebastian Gurin <sgu...@softpoint.org>



Zhou Renjian

--
http://webuzz.im/ Web IMs (G/A/M/Y)
http://j2s.sourceforge.net/ Java2Script

Sebastian Gurin

unread,
Jun 23, 2009, 10:07:20 PM6/23/09
to java2...@googlegroups.com
Thanks Renjian for the fast reply. It worked as spected!

BTW, Are this kind of bugs solved in some branch/trunk svn module? (i.e. from what svn url should I download the patched j2slib? - sorry i'm new with svn...)

thanks in advance. I will let you know when I reach to a decent yui widget porting to java2script... It is looking good ....

On Wed, 24 Jun 2009 09:30:31 +0800
Zhou Renjian <zhour...@gmail.com> wrote:

> Object.prototype.to$tring = Object.prototype.toString;
> Object.prototype.toString = function () {
> if (this.__CLASS_NAME__! = null) {
> return "[" + this.__CLASS_NAME__ + " object]";
> } else {
> return this.to$tring ();
> }
> };

--
Sebastian Gurin <sgu...@softpoint.org>

Zhou Renjian

unread,
Jun 23, 2009, 11:43:20 PM6/23/09
to java2...@googlegroups.com
Not committed to the SVN yet. And the patched j2slib is not available at the moment.

Regards,

Zhou Renjian

--
http://webuzz.im/ Web IMs (G/A/M/Y)
http://j2s.sourceforge.net/ Java2Script


Reply all
Reply to author
Forward
0 new messages