That snippet you are refering to is a bad example.

1.Do never ever extend Object in JavaScript.

Why? http://erik.eae.net/archives/2005/06/06/22.13.54


2. The JSON example is wrong as well. One value is a function, but 
functions are not allowed as value in JSON. One value is a RegExp object 
(neither allowed) and for the keys the quotes are missing.

http://json.org/

Having seen that I wouldn't trust that anyway.


-- Klaus




Carlos Aguayo schrieb:
> Hi everyone,
> If I attach a function to Object.prototype outside the
> $(document).ready function, it gets executed when I load the page, is
> this a bug?
> 
> Example:
> 
> <html>
> <head>
>     <%@ include file="/jquery/jquery-1.0.1.js" %>
> <meta http-equiv="content-type" content="text/html" />
> </head>
> <body>
> 
> <script type="text/javascript">
> Object.prototype.foo = function(){
>   alert('foo');
> };
> </script>
> </body>
> </html>
> 
> I get the alert as soon as the page gets loaded, if I move it inside a
> $(document).ready function, everything is fine then.
> 
> Carlos
> 
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
> 

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to