[thelist] Javascript object / prototype question

John Lauck recaffeinated at gmail.com
Thu Jan 10 11:20:39 CST 2008


Yes, that's the issue.  I use jQuery and as soon as you open another
function() { ...  } you can no longer use your `this` variable.  I assumed
that the new variable is just a reference, so it's not actually copying the
data to a new variable and that the reference is cleaned up when the
function ends.  Those are the two issues.  However, I've seen it used in
lots of scripts, so unless there's some sort of cleanup I'm unaware of?

On Jan 10, 2008 12:11 PM, Matt Warden <mwarden at gmail.com> wrote:

> 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.
> --
>
> * * Please support the community that supports you.  * *
> http://evolt.org/help_support_evolt/
>
> For unsubscribe and other options, including the Tip Harvester
> and archives of thelist go to: http://lists.evolt.org
> Workers of the Web, evolt !
>



More information about the thelist mailing list