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)
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
List of users who liked
00