JavaScript

OwnMemo Self-flowing SC

class Contract {
  constructor({event, contract}) {
    this.event = event;
    this.contract = contract;
  }
  occurrenceEvent() {
    this.event();
    this.executionContract_();
  }
  executionContract_() {
    this.contract();
  }
}

const p1 = {money:1000, colaStock:2};
const p2 = {money:1000, colaStock:5};

//event => send money
//contract => exchange money and cola.

const sampleContract = new Contract({
  event: () => {
    p1.money -= 100;
    p2.money += 100;
    console.log('send money')
  },
  contract: () => {
    p2.colaStock -= 1;
    p1.colaStock += 1;
    console.log('executionContract')    
  }
});

sampleContract.occurrenceEvent();
//check result
console.log(p1)
console.log(p2)