Works fine for me. I suspect that there may be some issue with some of your
other code somewhere.

Try opening a new JS file and using:
--- code -->
Object.prototype.getKeys = function(){
    var arr = [];
    $.each(this, function(k){ if(k!='getKeys') arr.push(k) });
    return arr;
}


$(function(){
    var x = {a: '1', b: '2', c: '3'};
    alert(x.getKeys())
})

<--- code --

It should alert "a,b,c"

Also, I had to edit the function a bit. Because of how the prototype works,
it adds the function name to the list of keys, so you have to filter that
out of there.

On Thu, Dec 11, 2008 at 2:30 PM, Bill <bllfr...@gmail.com> wrote:

>
> Thanks Eric, that's definitely a more jQuery-centric approach.
>
> But the Javascript error persists.
>
> On Dec 11, 11:24 am, "Eric Garside" <gars...@gmail.com> wrote:
> > Try:
> >
> > Object.prototype.getKeys = function(){
> >     var arr = [];
> >     $.each(this, function(k){ arr.push(k) });
> >     return arr;
> >
> >
> >
> > }
> > On Thu, Dec 11, 2008 at 2:17 PM, Bill <bllfr...@gmail.com> wrote:
> >
> > > If you know of another way of accomplishing this using jQuery, please
> > > let me know!
> >
> > > On Dec 11, 11:12 am, Bill <bllfr...@gmail.com> wrote:
> > > > Hi all,
> >
> > > > I extended the Object object with a method called getKeys() that
> works
> > > > like Perl's keys() function -- given a hash, or associative array,
> the
> > > > method returns an array containing all keys:
> >
> > > > Object.prototype.getKeys = function() {
> > > >         var arr = new Array();
> > > >         for (var s in this) {
> > > >                 if (this.hasOwnProperty(s)) arr.push(s);
> > > >         }
> > > >         return arr;
> >
> > > > }
> >
> > > > However, when I include this function definition anywhere in a page,
> > > > jQuery reports the following error:
> >
> > > > name.replace is not a function
> > > > name = name.replace(/-([a-z])/ig, function(all, letter)
> > > > {            jquery-1.2.6.js (line 1115)
> >
> > > > Any idea why this might be happening?
> >
> > > > Thank you kindly,
> >
> > > > --Bill
> >
> > --
> > Eric Garside
> > Front End Developer
> > LabPrints
>



-- 
Eric Garside
Front End Developer
LabPrints

Reply via email to