Tarek Ziadé wrote:
>Jean-Marc Orliaguet wrote:
>
>
>
>>[cut]
>>except that 'Form' is not a class (as in Class.create()), it's a plain
>>javascript object
>>
>>
>
>Form is the same thing than a class (i didn't put a C but a c) in our
>use: a namespace that gathers methods and
>that we can instanciate with 'new' if needed, or use over.
>
>Form as a matter of fact, is used like a class:
>
>Form.serialize(my_form_instance)
>
>Class is a namespace used to create new classes with initialize(), the
>only difference is that you have initialize() in Class
>
>
>
>>[cut bunch of code lines]
>>if you don't have anything to initialize, you don't need a class just
>>to create namespaces.
>>
>>
>
>because creating a class is not "just to create namespace". it is also
>to gather some functions together,
>that are related, and might interact. Those kind of elements need to
>evolve, might use common attributes later,
>call each other, etc, etc..
>
>So, I think i can push it up a bit and say that we can even have a base
>class for all our class with a non mandatory initialize method
>to facilitate unittesting, common needs and more important to facilitate
>the comprehension and evolution.
>
>Anyway, it's all about organizing the code, really.
>
>Now with javascript you can have functions hooked on variables, arrays,
>or anything you wish.
>So you can create namespaces from and for anything you want indeed.
>
>But we need methodology and an explicit way to gather js code together,
>over scriptaculous/prototype,
>and the way you proposed it (ie extending existing objects, or the first
>form you proposed by creating objects
>dedicated to a single function) is not what is wished because it might
>lead to redundancy, by hooking a
>function to a namespace on the fly without beeing integrated within a
>growing framework of classes.
>
>The main problem we have with javascript is that people add and hook
>pieces of js code to improve an UI,
>and sometimes do something that was previously done somewhere else, just
>because they don't have the
>overall sight of what exists, wich is all over the place.
>
>So having a CPSFormController (ok ok, no initialize() who cares) within
>CPSDocument
>and start gathering there js code done over forms is the only way to go
>so the guy behind will reuse
>it and possibly extend it a bit (and maybe add initialization code then,
>who knows ;) ).
>
>And its also the only way to go, to start unit testing everything.
>
>Now i know a lot of people don't care about Js at all, and they hate
>coding it (and i am sorry to bug dev ML again
>with one more message about js), but it's not harder than python or css
>to have a few good pratices.
>
>Anyway, maybe we can continue this talk out of the dev list Jean Marc :)
>
>Tarek
>
>
>
Tarek,
you only need to use a class if you want to pass some arguments to the
constructor otherwise use a literal object like
var CPSMystuff = {...}
Besides, your pattern creates memory leaks!, if you instanciate a new
object or a class just to simulate a namespace, your browser will run
out of memory sooner or later.
think about what happens when you do:
var CPSMyStuff = Class.create();
CPSMyStuff.prototype = { buttonClick: function () {
...
}
}
var my_stuff = new CPSMyStuff(); <==== put that in a loop and what
your browser die...
my_stuff.buttonClick()
in that particular case you should use:
var CPSMyStuff = {};
CPSMyStuff.buttonClick = function() { ... }
/JM
Hosting: Nuxeo: Zope service provider