jakesgordon/javascript-state-machine — pull request #40 by jessevogt (2013-01-19 05:11:34+00:00)
Title: Possible fix for Issue #39

In some cases it is desirable to be able to call event methods directly
into a method like setTimeout to trigger an event in the future.
Currently, this will cause an exception since the 'this' in buildEvent
will become the root object (window in a browser) and when it tries to
call this.cannot will throw an exception since it does not exist. Since
buildEvent returns a function it is possible to set the context
correctly in cases where a custom prototype is not being used by taking
advantage of closures.

Added tests to illustrate the issue with calling an event name directly
from a handler that uses a global scope: setTimeout.

NOTE: When "subclassing" StateMachine by providing your own prototype,
the problem will still exist since there is no direct context to pass
to the buildEvent method. The workaround is to wrap the event call in a
function - i.e. setTimeout(function () { sm.event(); }, 1000). The test
added under test_classes does this.

Added test that shows error when event is passed to setTimeout to be called when timer finishes

added test case for calling event name from global scope for class tests

When not using prototypes, pass context to buildEvent so events can be called directly from methods in the global scope: i.e. setTimeout

When not using prototypes, pass context to buildEvent so events can be called directly from methods in the global scope: i.e. setTimeout