var a = someObject.clone();
and
var a = clone(someObject);
Is it merely because you think it makes more semantic sense or . . . ? I
don't know why we would want to add more complexity to the code base for
something that isn't really giving us anything more. Please tell me what I
am missing, because I am sure there is something (it's late and my brain
doesn't function that well at this time of the morning).
Jason Bunting
> No virus found in this incoming message.
> Checked by AVG.
> Version: 8.0.100 / Virus Database: 270.3.0/1505 - Release Date: 6/16/2008
> 7:20 AM
It's almost the hallmark of MochiKit, that it _doesn't_ pollute the
global namespace, like a lot of other libraries do. The problem in
mocking around with core prototypes, is that you can break code that
would otherwise work. Of course, you can't run Mochikit together with
Prototype today either, but that's the fault of Prototype and not of
Mochikit.
Besides that, what's the benefit of writing thing the other way around
anyway? Mochikit uses a function-oriented syntax, while jQuery use an
object-oriented syntax. I find that this helps me to think
function-oriented, rather than object-oriented, and generally I think
that's a good thing.
( An interesting blog post about that topic exactly:
http://michaelfeathers.typepad.com/michael_feathers_blog/2008/05/are-fp-and-oo-i.html
)
--
troels
True, that _is_ something that can't be done with function-oriented
syntax. Personally, I'm not that found of this "fluent interfaces"
style; I think it works fine for simple cases, but lose it's punch
when things get more complex. Plus it can get a bit unintuitive, when
taken out of context. But I understand, that some people like it.
The way jQuery's api works, should make it possible to provide some of
these things without messing with built-in prototypes, I reckon? You
could simply return wrapper objects, which have the methods available?
I don't even remember if jQuery does this?
On Tue, Jun 17, 2008 at 5:07 PM, machineghost <machin...@gmail.com> wrote:
>
> Actually, come to think of it 5.counter() wouldn't even work (since 5
> is scalar, it doesn't inherit object.prototype methods). But
> hopefully you get the idea.
It works. 5 is a scalar, but it's automagically wrapped in an object,
when used as such.
--
troels
If you like that style of programming, I think you'd be better off
using one of these other libraries instead of MochiKit. At least their
mailing list wouldn't be hostile to the basic idea of modifying
built-in prototypes. ;-)
But I'm all for collaboration, cross-library compatibility and a free
exchange of ideas and code between these (quite similar) JavaScript
projects. If there is some clever way of bridging the gap or reusing
code I think it is worth having a look at. If only to allow
MochiKit-based code to run in environments where jQuery or Prototype
are already entrenched.
Question: Is mocking with the built-in object prototypes compatible with JS 2.0?
Cheers,
/Per