4 ms·
For #1 you can just use a closure. For #2, the method documented in http://stackoverflow.com/questions/972/adding-a-method-to-an-existing-object http://stackov
by btilly 16y ago
For #1 you can just use a closure.
For #2, the method documented in http://stackoverflow.com/questions/972/adding-a-method-to-an-existing-object http://stackoverflow.com/questions/972/adding-a-method-to-an... doesn't seem so bad to me.
object.methodname = new.instancemethod(function, object, class)
It may be deprecated. But it still works.
- deleted 16y ago[deleted]
- cturner 16y ago> For #1 you can just use a closure. I don't think that will work. See the discussion about rebinding in the post or elsewhere in the thread.
- btilly 16y agoIt is unclear to me what you think doesn't work. A closure can easily store state. As you yourself demonstrate in your rebinding example, you can store and mutate scope if you use a mutable datastructure (like a list) to avoid rebinding problems. Perhaps if you gave an example of what you think doesn't work, I might understand your point.