Connecting Tech Pros Worldwide Forums | Help | Site Map

Is it not well to extend Object.prototype derictly?

jidixuelang@gmail.com
Guest
 
Posts: n/a
#1: Aug 12 '07
As I know,it's not well to extend Object.prototype derictly.
In the Prototype(JS Framewoke),there is no extend Object.prototype.
It only add some static method for Object class.
I want to konw the reason.Who can give me some advise!?


Martin Honnen
Guest
 
Posts: n/a
#2: Aug 12 '07

re: Is it not well to extend Object.prototype derictly?


jidixuelang@gmail.com wrote:
Quote:
As I know,it's not well to extend Object.prototype derictly.
In the Prototype(JS Framewoke),there is no extend Object.prototype.
It only add some static method for Object class.
I want to konw the reason.Who can give me some advise!?
for..in enumeration will enumerate the properties added to
Object.prototype, try e.g.

Object.prototype.foo = function () { };
for (var propertyName in { bar: 1}) {
alert(propertyName);
}

and it will alert 'foo' as well as 'bar'.



--

Martin Honnen
http://JavaScript.FAQTs.com/
dhtmlkitchen@gmail.com
Guest
 
Posts: n/a
#3: Aug 12 '07

re: Is it not well to extend Object.prototype derictly?


On Aug 12, 7:08 am, Martin Honnen <mahotr...@yahoo.dewrote:
Quote:
jidixuel...@gmail.com wrote:
Quote:
As I know,it's not well to extend Object.prototype derictly.
In the Prototype(JS Framewoke),there is no extend Object.prototype.
It only add some static method for Object class.
I want to konw the reason.Who can give me some advise!?
>
for..in enumeration will enumerate the properties added to
Object.prototype, try e.g.
>
Object.prototype.foo = function () { };
for (var propertyName in { bar: 1}) {
alert(propertyName);
>
}
>
and it will alert 'foo' as well as 'bar'.
>
This is my thinking.

Google: Object.prototype is verboten!

Until ECMAScript provides access to the DontEnum flag,
Object.prototype should not be modified.

Adding a static property to Object constructor function would not be
harmful.

Object.poop = "hearin aid umbrella";

But that would be fairly useless.



Closed Thread