Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //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;
- })();
- //encapsulating object
- var Machine = function(automatan){
- this.automatan = automatan;
- this.switch = function(){
- this.automatan = this.automatan.switchState();
- };
- };
- //automata switching back and forth
- /* var a = new FSA(8);
- a
- => { val: 8, next: null }
- a.setNext(4)
- a
- => { val: 8, next: { val: 4, next: null } }
- a.next.setNext(a)
- a
- => { val: 8, next: { val: 4, next: { val: [Circular], next: null } } }
- var c = new Machine(a)
- c
- => { automatan: { val: 8, next: { val: 4, next: [Object] } }, switch: [Function] }
- c.switch()
- c
- => { automatan: { val: 4, next: { val: [Object], next: null } }, switch: [Function] }
- c.switch()
- c
- => { automatan: { val: { val: 8, next: [Object] }, next: null }, switch: [Function] }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement