javascript. is it posible for one member of an object to access another member of that object withou

Posted by joox on Stack Overflow See other posts from Stack Overflow or by joox
Published on 2010-04-18T15:57:00Z Indexed on 2010/04/18 16:03 UTC
Read the original article Hit count: 297

Filed under:
|
|
|
|

For example:

var myObj={

  myValue="hola",

  asMember=function(){ alert( this.myValue ); }

};


myObj.asMember(); // will work fine

var asGlobal=myObj.asMember; // global alias for that member function
asGlobal(); // won't work in javascript (will work in AS3, but i need js now)

So the question is, can I rewrite asMember so that it could be called by global alias and without mentioning myObj at all? It's understood that if I define it:

asMember=function(){ alert( myObj.myValue ); }

it will work, but in my case, mentioning myObj is not acceptable even inside the function itself (because myObj may be reassigned later, but asGlobal won't change and should keep working)

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about closure