I looked at traits.js and I think it's very elegant.
Just one quick point though. Is encapsulation part of the solution, or
part of the problem?
The use of libraries like traits.js to construct object properties and
methods is well established, but in my view these techniques have the
capacity to reduce interoperability rather than increase it. This is
because each object type will generally have a different underlying
structure, thus making it hard to write generic library functions to
manipulate them.
It may sound heretical, but I believe using a generic (hierarchical)
representation for all data can lead to some very relevant reuse/
interoperability benefits.
Regards
DS
--
To unsubscribe, reply using "remove me" as the subject.
I apologize for not focusing on traits.js itself - as I mentioned,
this is because I like it. The only minor quibble is that in general
I'm not comfortable with touching Object.prototype since it forces
every for..in construct to test for hasOwnProperty - although (i) this
is in reality an issue with the language itself and (ii) in any real-
life situation you have to do this anyway because you can never be
sure what other libraries do to Object.
As regards the wider issue of encapsulation in Javascript, I've got
quite strong views on this subject. These are based less on abstract
reasoning and more on many years of wrestling (in splendid isolation)
with these issues in a working environment.
I don't want to pollute the thread, so I'll just say that when it
comes specifically to the web, the undoubted benefits of encapsulation
are probably outweighed by disadvantages in terms of data portability
and the ability to combine code from different environments.
I'm happy to expand offline if you like (david-lmframework-com).
Best
DS
I apologize for not focusing on traits.js itself - as I mentioned,
this is because I like it. The only minor quibble is that in general
I'm not comfortable with touching Object.prototype since it forces
every for..in construct to test for hasOwnProperty - although (i) this
is in reality an issue with the language itself and (ii) in any real-
life situation you have to do this anyway because you can never be
sure what other libraries do to Object.
On Apr 14, 2:11 am, Tom Van Cutsem <to...@google.com> wrote:
What part of the library were you referring to when you
> mentioned being uncomfortable with touching Object.prototype?
>
My bad, I looked at the code without running it. I did a few tests and
can now see you're right.
Cheers
DS