开发者

javascript error: Invalid argument in IE on anonymous function

I'm getting a weird error in internet explorer (I tried on IE 8) Everything is fine with a different browser.

Invalid argument on a function similar to this one (I can't post the original one as it is from a non redistributable library which was originally obfuscated and compressed):

function createADiv() {
    var f = document.createElement('div');
    f.set = [function (z) { // error on this line
        f.style.width = z
    }, function (z) {
        f.style开发者_JS百科.height = z
    }];
    return f;
 }

The problem lies in the scope of f but I don't get why using f inside the anonymous functions shouldn't work.

Any ideas about how to circumvent this Internet Explorer bug?

I've checked other "invalid argument error" but this one seems to be a different case.

Thanks in advance


I think this is what you are trying to do:

function createADiv() {
    var f = document.createElement('div');
    f.set = {
        width: function (z) { // error on this line
            f.style.width = z
        }, 
        height: function (z) {
            f.style.height = z
        }
    };
    return f;
 }

now when you create a div you can do this:

var newDiv = createADiv();
newDiv.set.height("200px");

but to tell you the truth this is useless because javascript already does this:

newDiv.style.height = "200px";

there is not much difference


Not sure why, try re-writing it as this

function createADiv() {
    var f = document.createElement('div');
    f.set = [function a (z) { // error on this line
        f.style.width = z
    }, function b (z) {
        f.style.height = z
    }];
    return f;
 }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜