Jean-Marc Orliaguet wrote:
> Tarek Ziadé wrote:
>
>> Jean-Marc Orliaguet wrote:
>>
>>
>>
>>>>
>>>
>>> Your pattern of creating namespaces using classes creates memory
>>> leaks, I'll post a demo, so you can see for yourself..
>>
>>
>> you are still mixing concepts here, i am not creating namespaces by
>> creating classes, i am creating code organized
>> in classes and use it in my UI. classes organizations reveals therefore
>> a namespace when it's used.
>>
>>
>>
>
> what I'm saying is that using classes when you could use simple
> objects has a memory payload. (or maybe the classes are not supposed
> to be instanciated more than once?) and I'm not sure that I see what
> it adds compared to how it's done in prototype or in scriptaculous for
> instance...
>
there's a difference beside a few objects instanciated and tons of them
i think, otherwise nobody would ever ever call a 'new' in js
I'll put a section in the guide "when to choose a class what it brings,
a simple variable, etc..."
>
>> This is getting weird, you are going to work on a demo to prove that
>> this is wrong, over something
>> that has not be written yet, but 3 lines in a mail + what you thaught
>> you understood.
>>
>>
>
> well, you reacted first, on the 4 lines that I wrote (that I had
> copied from scriptaculous), and jumped on the class pattern to create
> namespaces ... :-)
>
> I simply wrote: "it is possible to create a namespace by creating a
> simple javascript object" and you wrote: "Hey wait! now we have
> scriptaculous we can use classes instead to achieve this.."
Since you proposed to do this, for a piece of inline javascript in a
page template:
<<<<<
var CPS = {
}
if (!CPS.document) { CPS.document = new Object() }
CPS.document.buttonClick = function () { ... }
try google on javascript + namespaces
<<<<<<<<<
What I meant (maybe not clearly enough i admit) by saying 'hey wait'
was: we have settled in CPSUtils
scriptaculous and prototype in order to gather into separated js script
file
cleaned and namespaced structures for all products, based on this framework.
Since in your lines, you didn't clearly mention scriptaculous/prototype,
i have reacted so people take the good habit to use what's available in CPS
instead of looking up google like you haved proposed,
and doing something localy over a page template.
Then I explained how a class could be created using prototype.
Then I said I would release a cps/js guideline to give info to people
on what exists.
Now something that was not discussed yet is how we would want
the form controller to be structured. But nevertheless, you reacted on
my class example,
talking about memory leaks, and we went trolling :)
>> Yes, but i still don't understand why you want to create more than one
>> instance here... and why you want to prove that creating a class
>> instance
>> is a memory leak... there's no crazy loop anywhere but in your mind
>> here ;)
>>
>>
>>
>
> this is exactly what I'm saying since the beginning, if you only need
> one instance, then you don't need to use Class.create(), you can just
> as well write:
>
> var MyStuff = {
> ...
> }
>
> and extend it with functions, variables, classes. But I don't see why
> you'd need to define a class to instanciate it only once?
>
it depends on the cases of courses, for example, a global registery
would be a singleton, a form controller might
be an extension of Form *or* a class, depending on what it does, etc...
Stay tuned for the paper.. It's a material based on what exists now in
CPS, we can work/discuss on then.
Tarek
_______________________________________________
cps-devel mailing list
http://lists.nuxeo.com/mailman/listinfo/cps-devel