20. function Auction(initialPrice) {
var currentPrice = initialPrice;
var bids = [];
var api = {};
api.bid = function (amount) {
currentPrice += amount;
bids.push(amount);
};
api.history = function () {
return bids.copy();
};
return api;
}
var auction = new Auction(10.0);
auction.bid(9001);
console.log(auction.history());
33. people = [Person.new(18), Person.new(22), Person.
new(65)];
canDrink = [];
for person in people
if (person.age > 20)
canDrink.push(person);
end
end
36. class Animal
constructor: (@name) ->
move: (meters) ->
alert @name + " moved #{meters}m."
class Snake extends Animal
move: ->
alert "Slithering..."
super 5
class Horse extends Animal
move: ->
alert "Galloping..."
super 45
sam = new Snake "Sammy the Python"
tom = new Horse "Tommy the Palomino"
sam.move()
tom.move()
37. Why are you writing your
Ruby in my JavaScript?