I noticed this behavior when I was playing with a deep cloning utility that I
found at:
http://www.bigbold.com/snippets/posts/show/749
so I just wanted to report it.
But yes, there has to do deep cloning, thanks!
Carlos
John Resig wrote:
It has to do with the fact that extending the Object.prototype has
negative consequences in almost all JavaScript code, regardless of the
library. The only way to iterate through the properties of an object
is by doing:
for ( var prop in obj )
and your 'foo' method will be included in every single one. What
result are you trying to achieve by extending the Object prototype?
There's most likely a better way to do what you're attempting to
achieve.
--John
On 9/22/06, Carlos Aguayo [EMAIL PROTECTED] wrote:
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
discuss@jquery.com
http://jquery.com/discuss/
--
John Resig
http://ejohn.org/
[EMAIL PROTECTED]
___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/
--
View this message in context:
http://www.nabble.com/bug-when-using-Object.prototype---tf2320206.html#a6455780
Sent from the JQuery mailing list archive at Nabble.com.
___
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/