开发者

Issue with Javascript closure

I have the following piece of code:

var blah = function(x, y){
    var e = {
       ox: x, 
       oy: y,
       etc.
    }
    return e;
开发者_如何学C};

However, I am getting an error "x is undefined". I thought that x and y should be available in inner scopes. Any help/explanation would be greatly appreciated!


Works fine for me. Did you use new and did you pass 2 params?

var blah = function(x, y){
    var e = {
       ox: x, 
       oy: y
    }
    return e;
};

z = new blah(1,2);
z.ox // 1
z.oy // 2
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜