JQuery Extend - operation is not supported in Firefox
When using JQuery, extending an object that has an overridden toString() function causes an "Operation is not supported" error in Firefox. However in Chrome it works fine. Is this a bug in JQuery or am I doing something wrong in the below code snippet?
var foo = function () {
var that = this;
that.toString = function () { return "foobar" };
return that;
}();
var foo2 = function () {
var that = this;
that = $.extend(true, {}, foo); // copy = options[ name ]; = "Operation is not supported" in Firefox 3.6.8开发者_如何学Go
return that;
} ();
alert(foo.toString()); //"foobar" in Chrome
alert(foo2.toString()); //"foobar" in Chrome
JQuery version 1.4.2
Many thanks,
Godders
When you call the anonymous function to get the value for "foo", the this
variable will be referencing the window object. Same goes for the anonymous function you call for "foo2". Thus, you're trying to extend the window object. Is that really what you want to do?
edit what Firefox seems to be tripping over is the attempt to copy the "sessionStorage" attribute of window
. Try adding this line:
var test = window['sessionStorage'];
and you'll get the exact same error.
精彩评论