jQuery.extend not working in Internet Explorer, but works in Firefox
I am attempting the following:
var Class1 = function() {}
Class1.prototype = {
MyMethod: function() { /* Do Stuff */ }
}
var Class2 = function() {}
Class2.prototype = {
AnotherMethod: function() { /* Do More Sweet Stuff */ }
}
jquery.extend(true, Class1, Class2);
I should now expect to be able to do the following:
var c = new Class1();
c.AnotherMethod();
In Firefox 3.6 this works just fine. In Internet Explorer 7 & 8 it says "Object doesn't support this property or method".
Am I misunderstanding how $.extend should work, or is IE behaving badly?
jQ开发者_开发知识库uery Version: 1.3.2
Thanks!
The first parameter to extend should be the target of extending Class1 to include Class2's properties. So, you should instead do:
var c;
jQuery.extend(c, Class1, Class2);
Unless you truly were intending to do a deep copy, in which case the first parameter should be true, and then the target, followed by the classes:
jQuery.extend(true, c, Class1, Class2);
This is all you need. Now Class1
should have been extended with the properties of Class2
jQuery.extend(Class1, Class2);
Check jQuery.extend documentation
I am using
Class2 = $.extend(true,{},Class1,Class2);
And i have same issue of method not found only in IE8. Firefox 3.6 is great same for Opera 10.
On top of everything, the error is inconsistent. When i refresh the page i might or not get the problem again.
I think that in my case it could be related to the way my script are loaded. But still.... IE is causing problem... again.
精彩评论