This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module zircon::profile { | |
// === Imports === | |
use std::string::String; | |
use zircon::profile_cap::{Self, ProfileCap}; | |
// === Structs === | |
/// The user's Profile. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Player { | |
constructor (name, points, gems) { | |
this.name = name; | |
this.points = points; | |
this.gems = gems; | |
} | |
accept (visitor) { | |
visitor.visit(this); | |
} | |
getName () { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const datastore = { | |
process: function () { | |
this.connect(); | |
this.select(); | |
this.disconnect(); | |
return true; | |
} | |
}; | |
function inherit(proto) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person { | |
constructor (name, street, city, state) { | |
this.name = name; | |
this.street = street; | |
this.city = city; | |
this.state = state; | |
} | |
hydrate () { | |
const memento = JSON.stringify(this); | |
return memento; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Bidder { | |
constructor (name) { | |
this.name = name; | |
this.auction = null; | |
} | |
bid (amount, to) { | |
this.auction.send(amount, this, to); | |
} | |
offer (amount, from) { | |
console.log(from.name + " offered " + amount); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Context { | |
constructor (input) { | |
this.input = input; | |
this.output = 0; | |
} | |
startsWith (str) { | |
return this.input.substr(0, str.length) === str; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function copy(x) { return x; } | |
function cut(x) { return x; } | |
function paste(x) { return x; } | |
class Command { | |
constructor (execute, value) { | |
this.execute = execute; | |
this.value = value; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ATM { | |
constructor(amount) { | |
this.amount = amount; | |
console.log("Requested: $" + amount + "\n"); | |
} | |
get (bill) { | |
const count = Math.floor(this.amount / bill); | |
this.amount -= count * bill; | |
console.log("Dispense " + count + " $" + bill + " bills"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Shipping { | |
constructor() { | |
this.method = ""; | |
} | |
setStrategy (method) { | |
this.method = method; | |
} | |
calculate (box) { | |
return this.method.calculate(box); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TrafficLight { | |
constructor() { | |
this.count = 0; | |
this.currentState = new Red(this); | |
} | |
change (state) { | |
// limits number of changes | |
if (this.count++ >= 10) return; | |
this.currentState = state; | |
this.currentState.go(); |
NewerOlder