开发者

Passing object to a function as an argument in javascript

I am trying to pass an object to a function but when I try to output the object it says "undefined". Here is an 开发者_运维问答example:

// object defined
this.object = new Ext.data.JsonStore({
  //some store properties
});

// printing object
function printObject (obj) {
   alert(obj); // my output is "undefined"
}

// trying to pass the object
printObject(this.object);

Can anyone tell me how can I pass an object as an argument? thanks in advance


what is the context here, what does this refer to, another object? try calling it something other than 'object', perhaps 'data'. not 100% sure, but I think 'object' may be reserved.


possibly it is the function pringObject (rather than printObject) that is undefined.


Try this:

var obj = new Ext.data.JsonStore({
  //some store properties
});

So that obj is implicitly casted to an object of type returned by JsonStore

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜