in i want to alert the 'image' which is the object name, how can i access with this
?
Objectswitch={
'image':
{
addCount:function(){
alert('count');
},
addCountandCreate:function(){
this.addCount();
alert(this);
}
开发者_开发技巧 }
}
Sorry, you can't with that structure. this
refers to the object: {addCount:, addCountandCreate:}
and JS has no way to say this.parentObject
(which doesn't make sense anyway since an object can have multiple references)
You'll need to add the name as a property of the object:
var imageObj = {
name: "image",
addCount:function(){
alert('count');
},
addCountandCreate:function(){
this.addCount();
alert(this.name);
}
}
you can then reference that object from within another, of course:
ObjectSwitch = {
"image": imageObj
}
精彩评论