constant switching automata javascript
//Implementation of FSA, via a linked node-like interface.
var FSA = (function(){
function FSA(val){
this.val = val;
this.next = null;
}
FSA.prototype.setNext = function(val){
this.next = new FSA(val);
};
//needs to be appended inside controlling object
FSA.prototype.switchState = function(){
if(this.next){
return this.next;
}
};
return FSA;
})();
//constant reverse switching
/* var a = new FSA(8);
a
=> { val: 8, next: null }
a.setNext(3)
a
=> { val: 8, next: { val: 3, next: null } }
a.next.next = a
=> { val: 8, next: { val: 3, next: [Circular] } }
var b = a.switchState
b
=> [Function]
var b = a.switchState()
b
=> { val: 3, next: { val: 8, next: [Circular] } }
var b = a.switchState()
b
=> { val: 3, next: { val: 8, next: [Circular] } }
var b = a.switchState()
b
=> { val: 3, next: { val: 8, next: [Circular] } }
var b = b.switchState()
b
=> { val: 8, next: { val: 3, next: [Circular] } }*/