On Aug 13, 2012 12:37 PM, "Pepe Aracil" <pepe.aracil.go...@gmail.com> wrote:
>
> Hi Daniel.
>
> I did some experiments calling python methods from javascript code.
> I think you need wrap your method callback into anonymous function (see
setTimeout example)
>
> Here are the examples:
>
> from __pyjamas__ import JS
>
>
> class Cls():
>   def __init__(self, name):
>     self.name = name
>
>   def sum(self, a, b):
>     print "Met from %s instance" % self.name
>     return a + b
>
>   def touch(self):
>     print "Touch called from %s instance." % self.name
>
>
> if __name__ == '__main__':
>   c = Cls("foo")
>   res = 0
>
>   # This works
>   res = JS("""
>     @{{res}} = @{{c}}.sum(5,10)
>     """)
>   print res
>
>   # This works
>   JS("""
>     @{{c}}.touch()
>     """)
>
>   # This don't work
>   JS("""
>     setTimeout(@{{c}}.touch, 3000)
>     """)
>
>   # This works
>   JS("""
>     setTimeout(function(){@{{c}}.touch()}, 3000)
>     """)

Pepe,

Take a look at:

https://github.com/pyjs/pyjs/pull/752#issuecomment-7448404

... no need for setTimeout/etc :-)

-- 

C Anthony

-- 



Reply via email to