Skip to content

Commit c561d0f

Browse files
committed
Prefer es5 Array.isArray(obj) rather than problematic (obj instanceof Array)
Fixes Issue jakesgordon#88 "Multiple 'from' and 'to' states for a single event gives error in node cmd with jasmine"
1 parent bcf3967 commit c561d0f

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

state-machine.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
var transitions = {}; // track events allowed from a state { state: [ event ] }
4747

4848
var add = function(e) {
49-
var from = (e.from instanceof Array) ? e.from : (e.from ? [e.from] : [StateMachine.WILDCARD]); // allow 'wildcard' transition if 'from' is not specified
49+
var from = Array.isArray(e.from) ? e.from : (e.from ? [e.from] : [StateMachine.WILDCARD]); // allow 'wildcard' transition if 'from' is not specified
5050
map[e.name] = map[e.name] || {};
5151
for (var n = 0 ; n < from.length ; n++) {
5252
transitions[from[n]] = transitions[from[n]] || [];
@@ -75,7 +75,7 @@
7575
}
7676

7777
fsm.current = 'none';
78-
fsm.is = function(state) { return (state instanceof Array) ? (state.indexOf(this.current) >= 0) : (this.current === state); };
78+
fsm.is = function(state) { return Array.isArray(state) ? (state.indexOf(this.current) >= 0) : (this.current === state); };
7979
fsm.can = function(event) { return !this.transition && (map[event].hasOwnProperty(this.current) || map[event].hasOwnProperty(StateMachine.WILDCARD)); }
8080
fsm.cannot = function(event) { return !this.can(event); };
8181
fsm.transitions = function() { return transitions[this.current]; };

state-machine.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)