}).call(this.foo2); ---> }).call(this);

--
Ariel Flesler
http://flesler.blogspot.com/

On 18 jun, 17:45, meppum <[EMAIL PROTECTED]> wrote:
> I have the below code and I'd like the alerts to say "hi" then "hi
> there" but it looks like I'm losing scope inside the anonymous
> function. This is a simplified version of a more complicated function
> I am trying to implement. I'm not sure if jquery can help with this,
> and I'm fine using vanilla JS code, but I've read the scoping
> tutorials and can't figure it out...
>
> <html>
>     <head>
>         <script type="text/javascript">
>                 function myFunction() {
>                     this.foo = "hi";
>                     this.foo2 = foo2Function;
>                 }
>
>                 function foo2Function() {
>                     (function() {
>                         this.foo = "hi back";
>                     }).call(this.foo2);
>                 }
>
>                 function test() {
>                     var obj = new myFunction();
>
>                     alert(obj.foo);
>
>                     obj.foo2();
>
>                     alert(obj.foo);
>                 }
>         </script>
>     </head>
>     <body onload="test()">
>
>     </body>
> </html>

Reply via email to