Thank you for reading it so carefully.
I'm not good at English but I will try my best to describe it clearly.

1. It's a bit like a dog riding a bicycle.
I completely agree with you.
But don't you think it is a bit like "Class.create" in prototype?
I will never use it in my program myself.
It is just "a interesting code" for me.
I prefer to use functional programming(Later I may show you a
interesting implement of currying) or the following:
function class1()
{
    class2.call(this)//inherit
    class3.call(this)//multi-inherit
    this.v1=1;//public
    var v2=2;//private
}
class1.prototype.v3//do not use


2.It is used to create js class like class in java or c#
So member functions can only visit global variables no matter where
Initalizer is defined.

3.Eval cost much and is not friendly to debugger but it is the only
way to point [[scope]] to a normal object in scope chain.

4.I think we can ignore the cost in main script.
But in fact it is even worse, the code for classes defined in this way
is evaluated more than twice.
It is evaluated every time when creating a object from the class.


5. Sorry,I forget to delete "ret.prototype=Initalizer.prototype;"

6.I don't think it is a bad style.In fact I like it very much......
:-)


On 5月14日, 下午6时54分, "T.J. Crowder" <[EMAIL PROTECTED]> wrote:
> Hi,
>
> It's certainly an interesting approach. :-)  Some observations:
>
> 1. It works; kudos.  It's a bit like a dog riding a bicycle, but
> still...
>
> 2. You'd have to document like *crazy* the fact that the code passed
> to the Class function *isn't* evaluated in the apparent lexical scope,
> but rather in the really very special lexical scope created within the
> Class function.  (Well, actually, it's evaluated in both, but the
> second is the one that will get used.)  Users failing to appreciate
> the subtleties related to that would tend to run into difficult-to-
> track-down bugs, particularly related to closures.  And *they'd* have
> to document it like crazy in their own code, as well, so anyone
> picking it up is forewarned.  Maintenance nightmares loom.
>
> 3. Debugging would tend to be fairly difficult, what with the class
> and all of its member functions being within the eval, not (again)
> actually where they appear to be.  I expect over time that JavaScript
> debuggers will handle debugging eval'd code more and more elegantly
> (certainly there is effort being made there), but for the moment...
>
> 4. The code for classes defined in this way is evaluated twice, once
> in the course of the main script being evaluated, and then again when
> Class is called.  Given that page load times are king, this isn't
> ideal although I'm sure it happens fairly quickly.
>
> 5. Regarding this:
>
> >         ret.prototype=Initalizer.prototype;
>
> >         for(var p in
> > Initalizer.prototype)ret.prototype[p]=Initalizer.prototype[p];
>
> Given the assignment in the first line, what is the purpose of the
> loop following it?  Genuine question, not a dig -- am I missing a
> subtlety?  Seems likely I am.
>
> 6. Style point:  You declare 'p' at least three times, which various
> lint tools may complain about although it's allowed by the ECMA spec.
> (It Really Shouldn't Be, but it is.)
>
> Thanks for the post -- it's interesting.  Very much about tradeoffs,
> cost/benefit.  For me, most of the time, I think the cost would tend
> to be too high, but it's still an interesting approach to the old
> problem.
> --
> T.J. Crowder
> tj / crowder software / com
>
> On May 13, 7:22 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote:
>
>
>
> > /*author:[EMAIL PROTECTED]/
> > function Class(Initalizer,SuperClasses)
> > {
> >         if(!SuperClasses)SuperClasses=[];
> >         var ret=function(){
> >                 for(var i=0;i<SuperClasses.length;i++)
> >                 {
> >                         SuperClasses[i].call(this);
> >                 }
>
> >                 var $private={};
> >                 var $public=this;
> >                 var $static=ret;
>
> >                 with($static){
> >                         with($private){
> >                                 with($public){
> >                                         
> > eval("("+Initalizer+").apply(this,arguments)");
> >                                 }
> >                         }
> >                 }
> >                 return this;
> >         }
>
> >         ret.prototype=Initalizer.prototype;
>
> >         for(var p in
> > Initalizer.prototype)ret.prototype[p]=Initalizer.prototype[p];
> >         for(var p in Initalizer)ret[p]=Initalizer[p];
> >         for(var i=0;i<SuperClasses.length;i++)
> >         {
> >                 for(var p in SuperClasses[i].prototype)
> >                 {
> >                         ret.prototype[p]=SuperClasses[i].prototype[p]
> >                 }
> >         }
> >         return ret;
>
> > }
>
> > /*
> > function alert(s)
> > {
> >         WScript.echo(s);}
>
> > */
>
> > /***********************************************
> > Example:public static private
> > ************************************************/
>
> > var test1=new Class(function(){
>
> >         //v1 is public
> >         $public.v1=1;
>
> >         //v2 is private
> >         $private.v2=2;
>
> >         //define public variable with this
> >         this.vv1=2;
>
> >         //public function member
> >         $public.show=function(){
> >                 //visit public and private variable
> >                 alert(v1);
> >                 alert(v2);
> >         }
> >         $public.set_static=function(v){
> >                 $static.v3=v;
> >         }
>
> > });
>
> > var obj=new test1();
>
> > //visit public variable
> > alert(obj.v1);
> > alert(obj.vv1);
>
> > //try to visit private variable
> > alert(obj.v2);
>
> > //call public member function
> > obj.show();
>
> > //set static variable
> > obj.set_static(10);
> > //visit static variable from class
> > alert(test1.v3);
>
> > /***********************************************
> > Example:multi-inherit
> > ************************************************/
> > var parent=function(){this.v4=6};
> > parent.prototype.v5=1000;
>
> > var test2=new Class(function(){
> >         $public.show2=function(){
> >                 alert(this.v1);
> >                 alert(v4);
> >                 alert(v5);
> >         }
>
> > },[test1,parent]);
>
> > var obj=new test2();
> > obj.show2();- 隐藏被引用文字 -
>
> - 显示引用的文字 -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Spinoffs" group.
To post to this group, send email to rubyonrails-spinoffs@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to