As I know,it's not well to extend Object.prototype derictly.
Depends. So far, whereever prototype objects are extended in a library,
precautions must be taken that the newly added enumerable properties are
excluded from for...in iteration and ignored with the `in' operation if so
desired.
I think it is OK to augment a built-in prototype object (including
Object.prototype) as long as the vendor of the library documents that and
provides means to work around this issue (say, a forEach() method accepting
an object and a callback reference.)
In the Prototype(JS Framewoke),there is no extend Object.prototype.
It only add some static method for Object class.
That only appears so. There are no classes and no static methods in the
ECMAScript implementations Prototype.js supports. They "extend" the Object
constructor, i.e. augment to the Function object it refers to with
user-defned properties. Adding properties to an object is a fairly normal
operation with prototype-based inheritance as there is no class binding to
forbid that.
They do add properties to several other built-in objects though, including
Number.prototype, String, String.prototype, and Array.prototype. That
latter breaks for...in iteration and the `in' operation if not explicitly
excluded by the programmer who is using that library. That programmer would
then have to wade through the obfuscated library code he is using in order
to make sure he covers all the library-defined properties, because the
library itself provides no such means.
I want to konw the reason.
See the signature below.
Who can give me some advise!?
Don't use Prototype.js or libraries based on it.
PointedEars