It doesn't make sense on Object.prototype. For example:

Object.prototype.keys = function(){
    var ret=[],p;
    for(p in this)
        if(Object.prototype.hasOwnProperty.call(this,p))
            ret.push(p);
    return ret;
}

function Employee(name){
    this.name = name;
}
Employee.prototype = {
    sayHello : function(){
       return "Hello! My name is "+ this.name;
    },
    job : "Engineer"
}

var p = new Employee("Peter");

console.log(p.keys().join());
---------------------------------------------------

Also, what would be the point of using it on an Array?

var p = ['a','b','c'];

console.log(p.keys().join());  // 0,1,2

--------------------------------------------------

Or a regular function?

function foo() { this + " [stuff]" }

console.log(foo.keys().join());

--------------------------------------------

There is no point in augmenting every object in the language with
method(s) that have no meaning in that object's context

On Feb 28, 8:56 pm, Jason Persampieri <[email protected]> wrote:
> Just read Angus Croll's post on the new Object properties, 'keys' and
> 'getOwnPropertyNames'.
>
> http://javascriptweblog.wordpress.com/2011/02/28/javascript-object-ke...
>
> It got me thinking... I hadn't noticed until now, but it looks like all of
> the new properties (create/preventExtensions/etc) are implemented on Object,
> as opposed to Object.prototype.  Any insight as to why?  It may be just a
> personal preference, but I would *vastly* prefer obj.keys() over
> Object.keys(obj).
>
> _jason

-- 
To view archived discussions from the original JSMentors Mailman list: 
http://www.mail-archive.com/[email protected]/

To search via a non-Google archive, visit here: 
http://www.mail-archive.com/[email protected]/

To unsubscribe from this group, send email to
[email protected]

Reply via email to