P.js, an object oriented javascript system in 559 bytes!
an example:
// P.js exposes the `P` variable
(function()
{
var Animal = P(function(self)
{
self.init = function(name)
{
self.name = name;
};
self.move = function(meters)
{
console.log(self.name + " moved " + meters + "m.");
}
});
var Snake = P(Animal, function(self, base)
{
self.move = function()
{
console.log("Slithering...");
base.move.call(self, 5);
};
});
var Horse = P(Animal, function(self, base)
{
self.move = function()
{
console.log("Galloping...");
base.move.call(self, 45);
};
});
var sam = Snake("Sammy the Python"),
tom = Horse("Tommy the Palomino");
sam.move()
tom.move()
})();
i love it!
Commenti