from pythonscript import js js('var py = require("./py")') print "Testing decorators" def inc(fn): def the_fn(x): return fn(x) + 1 return the_fn @inc @inc def foo(x): return x print "foo(1) is", foo(1)
from pythonscript import js js('var py = require("./py")') print "Testing factorial" def factorial(n): if (n > 0): return n * factorial(n - 1) else: return 1 print "Factorial of 2 is", factorial(2) print "Factorial of 3 is", factorial(3) print "Factorial of 4 is", factorial(4) print "Factorial of 5 is", factorial(5)
def the_fn(*args, **kwargs): return fn(*js('[this].concat(args)'), **kwargs)