Thanks a lot for the great answer it pretty much completely answers my
question and you have some really good points about parts that I
hadn't considered. I've since restructured my extension into a wrapper
as I think it will work out better this way, but the
Function.methodize() function will be very helpful still with this new

What I am working on is a sproutcoreish variable/event binding system
built on prototype simple at first basically dealing with a few DOM
events and variable onchange events.

Thanks again,

On Sep 10, 2:36 am, "T.J. Crowder" <[EMAIL PROTECTED]> wrote:
> Hi Sean,
> > So far I have:
> > Object.extend(Object.prototype, {
> > ...
> Be *very* careful extending the Object prototype.  This is the
> prototype used for all JavaScript objects, which means that (for
> example) if you're using any 3rd party code that expects objects to be
> empty unless something is added to them, you'll break that code.
> That's why Prototype doesn't extend Object.prototype.  It extends
> Object itself (e.g., adding Object.isFunction and such), but not the
> prototype used for all objects.
> Prototype does extend Array.prototype, String.prototype,
> Function.prototype, and a couple of others.  It also extends the
> prototype of DOM elements when it can (it can't on IE).  This has
> actually caused some trouble and there's a move on to scale back, I
> think it's likely that at some stage Prototype will stop extending
> Array.prototype and DOM elements, going for wrapper objects instead.
> Getting to your actual question:
> > Given the amount that things like this are done in prototype I was
> > just wondering if there is a better way to accomplish this.
> Prototype uses the Function.methodize() function to achieve 
> this:http://www.prototypejs.org/api/function/methodize
> You write the function with the first parameter being the object to
> act on, and then you can turn that into a method of the object by
> using methodize().  methodize() returns a new function that will call
> the original function with "this" as the first parameter, passing
> through any other parameters it got as subsequent parameters after
> "this".  Prototype does this to put some of the standard static Math
> functions on the Number prototype as methods:
>     $w('abs round ceil floor').each(function(method){
>       Number.prototype[method] = Math[method].methodize();
>     });
> That code is a bit dense if you're new(ish) to Prototype, but for
> instance for the Math.abs() function, it does the same thing this line
> of code does:
>     Number.prototype.abs = Math.abs.methodize();
> Math.abs takes a number and returns the absolute value.  What
> methodize() does is create a function that passes "this" as the first
> (and in this case only) parameter to Math.abs() and return the result.
> The main reason Prototype uses methodize() is to provide static
> versions of methods like Element.addClassName(), and to also on some
> platforms provide an addClassName() method on extended element
> instances.
> What's your use case?  It's basically only useful if you have a bunch
> of functions that you then want to also make accessible as methods on
> an object...  Note that the methods end up being slightly less
> efficient, as they involve two function calls rather than one (a call
> to the method, which then just calls the static function).
> HTH,
> --
> T.J. Crowder
> tj / crowder software / com
> On Sep 9, 11:50 pm, sean <[EMAIL PROTECTED]> wrote:
> > I'm working on a custom extension of a couple of functions to the
> > Object class and was just wondering how prototype connects functions
> > such as Object.inspect(variable); to variable.inspect();
> > So far I have:
> > Object.extend(Object.prototype, {
> >         talk: function(object)
> >         {
> >                 if(typeof(this) != 'function')
> >                         object = this;
> >                 alert(object);
> >         }
> > });
> > var test = 'hi';
> > Object.talk(test);
> > test.talk();
> > This seems like it should work for simple cases but will quickly
> > become more complicated if I want more that just the one parameter.
> > Given the amount that things like this are done in prototype I was
> > just wondering if there is a better way to accomplish this.
> > Thanks,
> > - Sean
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 

Reply via email to