Tarek Ziadé wrote:
>Jean-Marc Orliaguet wrote:
>
>
>
>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..."
>
>
>
great, and add something about using the 'prototype' property on
instanciated objects to reduce memory usage.
http://www.webreference.com/js/column34/methods.html
>>>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
><<<<<<<<<
>
>
>
that was just an example, all the implementations I have seen so far use
the same pattern to create 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.
>
>
>
OK, then studying the pattern/layout used in prototype.js or
scriptaculous is a good start.
>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.
>
>
>
OK
>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 :)
>
>
>
well, since you did not have a clear object to attach your method to
(like a CPSForm for instance created for one CPSDocument form), it
appeared as though you had to instanciate your class just to get access
to that clickButton() thingie.
so yes, these should be classes, but the object must be designed first
and instanciated in a controlled way (when the HTML form is loaded), not
just when developer thinks "hey I need that clickButton() utility; I'll
just instanciate that CPSForm class ..), and the code gets called every
time the user moves the mouse.
>>>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
>
>
>
>
Okay
/JM
Hosting: Nuxeo: Zope service provider