HighDots Forums  

Re: Replacing a private function an keeping access to privatevariables

Javascript JavaScript language (comp.lang.javascript)


Discuss Re: Replacing a private function an keeping access to privatevariables in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
agendum97@gmail.com
 
Posts: n/a

Default Re: Replacing a private function an keeping access to privatevariables - 06-27-2008 , 05:53 PM






On Jun 26, 4:53*pm, Gregor Kofler <use... (AT) gregorkofler (DOT) at> wrote:
Quote:
How can I access a private variable when replacing a private function,
which originally had access to this variable, with another one? Or is it
just not possible?
If possible for your scenario, you could potentially use eval for
this. For example:


function MyClass(val)
{
var printIt = function () { window.alert("1:" + val); }
this.callPrintIt = function () { printIt(); }
this.setPrintIt = function (evalStr) { eval("printIt = " +
evalStr); }
}

var c = new MyClass("test");
c.callPrintIt();
c.setPrintIt("function () { window.alert(\"2:\" + val); }");
c.callPrintIt();


Thanks


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.