[thelist] Javascript object / prototype question
Matt Warden
mwarden at gmail.com
Thu Jan 10 11:11:09 CST 2008
On 1/10/08, John Lauck <recaffeinated at gmail.com> wrote:
> In the example below does this cause a memory problem on line 12. It's
> necessary to save the current object if you are using a lot of functional
> js, but does the local variable myobj get destroyed after the call to
> do_something()? My page seems to be running terribly slow but I can't tell
> if it's related to the external libs/plugins I'm using or my code.
>
> 1 <script>
> 2 function SomeApp(key) {
> 3 this.key = key;
> 4
> 5 this.globals = {
> 6 // set a bunch of globals
> 7 };
> 8 }
> 9
> 10 SomeApp.prototype = {
> 11 do_something: function() {
> 12 var myobj = this;
> 13 // do something with myobj
> 14 }
> 15 }
> 16
> 17
> 18 var AppInst = new SomeApp("keystring");
> 19 AppInst.do_something();
> 20 </script>
>
According to your code, no. But reading between the lines, you are
probably doing this because you need an outside reference to that
object (right?). Otherwise, I am not sure why you couldn't just use
"this". In this case, it may very well cause a memory issue
--
Matt Warden
Cincinnati, OH, USA
http://mattwarden.com
This email proudly and graciously contributes to entropy.
More information about the thelist
mailing list