Jean-Marc Orliaguet wrote:
> Tarek Ziadé wrote:
>
>> [big cut]
>>
>>
>>
>
> 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()
>
:)
why do you want to put that in a loop ?
sorry i don't get that point,
put a loop over any instanciation and it consumes memory, yes.
"my_stuff" is not intended to be created 10 000 times
(just one time, beside a few other vars created through all framework layer)
>
> in that particular case you should use:
>
> var CPSMyStuff = {};
> CPSMyStuff.buttonClick = function() { ... }
>
Jean-Marc,
i think you are mixing for this particular use case,
between the fonction concept, the class concept, and the namespace concept,
the objective is not to create one instance of a given class type for
just one function.
like i said you can hook javascript code any way you want. but we should
try to think o-o a bit here, for reusability, on the top of prototype
framework.
the o-o way would be to ask ourselves: where would the buttonClick
function fit the best ?
is it a simple, independant function ? or is it related to an object ?
could it be added in a class that gathers all functions aimed to
interact with forms, with the
whole container ?
can it evolve and start to interact with other functions ? etc...
I think we can discuss all this with the material i am doing in the
incoming CPS javascript guideline.
thanks for this feedback, i really think the guideline will be improved
through this kind of talks.
Tarek
_______________________________________________
cps-devel mailing list
http://lists.nuxeo.com/mailman/listinfo/cps-devel