Pyjamas doesn't seem to support either types module or get() method for binding a function/method to a class method. This makes the Strategy pattern impossible to implement in Pyjamas.
For example, using types module, a clean way to implement Strategy pattern in Python would be as follows:
instance = OrigObject()
instance.strategy = types.MethodType(strategyA, instance)
This runs fine in Pyjamas Desktop, but throws an import error in the browser:
ImportError: No module named types, types in context None
The alternative way is to use get() method for the function being bound:
instance.strategy = strategyA.get(self, OrigObject)
This too works great in Pyjamas Desktop, but throws a type error in Pyjamas:
TypeError: Object function ... has no method 'get'
Original issue: http://code.google.com/p/pyjamas/issues/detail?id=628 (July 05, 2011 14:40:28)
From atsep...@gmail.com on July 05, 2011 15:40:52:
Here is a modified version of helloworld example that uses Strategy pattern, it's a bit of overkill for this example, but it's simple and it works. This version relies on get() method. Tested it to work in Pyjamas Desktop.
From atsep...@gmail.com on July 05, 2011 15:44:42:
Here is an alternative version that uses types.MethodType() instead, it also works in Pyjamas Desktop.