Skip to content

Instantly share code, notes, and snippets.

@rramsden
Created January 13, 2011 00:37
Show Gist options
  • Save rramsden/777176 to your computer and use it in GitHub Desktop.
Save rramsden/777176 to your computer and use it in GitHub Desktop.
nested arguments in javascript
Class = {}
Class.new = function(object) { return Class.extend({}, object); }
Class.extend = function(parent, self) { // child = this
return (function() {
self.super = function() {
self.parent = parent(arguments);
}
self.initialize.apply(self, arguments);
return self;
});
}
var Person = Class.new({
name : '',
age : 0,
initialize : function(name, age) {
console.log('invoked person');
this.name = name;
this.age = age;
},
display: function() {
console.log('My name is ' + this.name + '. I am ' + this.age + ' years old.');
}
});
var Pirate = Class.extend(Person, {
ship: null,
initialize: function(name, age, ship) {
console.log('invoked pirate');
this.super(name, age);
this.ship = ship;
},
display: function() {
console.log("Yarrr, I'm the pirate " + this.name + " from the ship " + this.ship);
}
}
var PirateNinja = Class.extend(Pirate, {
clan: null,
initialize: function(name, age, ship, clan) {
console.log('invoked ninja');
this.super(name, age, ship);
this.clan = clan;
},
display: function() {
console.log("I am the legendary pirate "+this.name+" from the clan " + this.clan + " and currently on board the ship " + this.ship);
}
})
debugger
var pirate_ninja = new PirateNinja('Stan', 22, 'The Black Pearl', 'Matsumoto');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment