By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,501 Members | 1,660 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,501 IT Pros & Developers. It's quick & easy.

Is it not well to extend Object.prototype derictly?

P: n/a
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!?

Aug 12 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
ji*********@gmail.com wrote:
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/
Aug 12 '07 #2

P: n/a
On Aug 12, 7:08 am, Martin Honnen <mahotr...@yahoo.dewrote:
jidixuel...@gmail.com wrote:
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.

Aug 12 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.