| thelostdoom | 
			20.07.2011 21:21 | 
		 
		 
		
		 
		
		
			Extend через Object   
		
		
		
		Кто, что может сказать о так методе наследования  
Для меня оно более лаконично выглядит
 
Object.prototype.extend = function(Parent) {
	var F = function() { }
	F.prototype = Parent.prototype
	this.prototype = new F()
	this.prototype.constructor = this
	this.superclass = Parent.prototype
};
function Animal(name, walkSpeed) {
	// объявить приватную переменную
	var speed = walkSpeed
	// объявить открытую переменную
	this.distance = 0
	// добавить метод, использующий private speed
	this.walk = function(time) {
		this.distance = this.distance + time*speed
	}
	// добавить метод, использующий private name
	this.toString = function() {
		return name+" на расстоянии "+this.distance
	}
}
function Bird(name, walkSpeed, flySpeed) {
	// вызов родительского конструктора
	Bird.superclass.constructor.call(this, name, walkSpeed)
	this.fly = function(time) {
		this.distance = this.distance + time*flySpeed
	}
}
Bird.extend(Animal);
bird = new Bird("Птыц", 1, 10)
bird.walk(3)
alert(bird) // => Птыц на расстоянии 3
bird.fly(2)
alert(bird) // => Птыц на расстоянии 23
 
	 |