LoginSignup
0
0

More than 5 years have passed since last update.

OwnMemo Self-flowing SC

Posted at
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)
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0