//Unique array fonksiyonu Array.prototype.unique = function() { var unique = []; for (var i = 0; i < this.length; i++) { for (var j = i + 1; j < this.length; j++) { if (this[i] === this[j]) j = ++i; } unique.push(this[i]); } return unique; }; //Interface atama fonksiyonu Function.prototype.implements = function(interfaces) { var _implements = []; for (var i = 0; i < arguments.length; i++) { _implements = _implements.concat(arguments[i]); } _implements = _implements.unique(); this.__implements__ = _implements; //chaining return this; }; //Implementasyon fonksiyonu Function.prototype.ensureImplements = function(interfaces) { var _implements = []; for (var i = 0; i < arguments.length; i++) { _implements = _implements.concat(arguments[i]); } _implements = _implements.unique(); for (var i = 0; i < _implements.length; i++) { if (!(_implements[i] in this) && !(_implements[i] in this.prototype)) { throw new Error('Implementation failed, ' + _implements[i] + ' should be implemented'); } } }; //Kalıtım fonksiyonu Function.prototype.extends = function(parent) { this.prototype = Object.create(parent.prototype); this.prototype.constructor = this; //chaining return this; }; //Prototype ekleme fonksiyonu Function.prototype.proto = function(structure) { for (var item in structure) this.prototype[item] = structure[item]; //super methoda erişim this.prototype.__defineGetter__('super', function() { return this.__proto__.__proto__; }); //statiklere erişim this.prototype.__defineGetter__('self', function() { return this.constructor; }); //private method. this.prototype.abstract = function() { if (this.constructor == arguments[0].callee) throw new Error('You cannot create instance of an abstract class.'); }; //implementasyon kontrol this.ensureImplements(this.__implements__); return this; }; var iAnimal = ['speak', 'walk']; var iBird = ['fly']; function Animal() { //abstract kontrolü. this.abstract(arguments); alert('animal const'); } Animal.implements(iAnimal).proto({ speak: function() {}, walk: function() {} }); function Bird() { alert('bird const'); this.super.constructor.apply(this, arguments); } Bird.SPEAKER = 'cik cik'; Bird.extends(Animal).implements(iBird).proto({ speak: function() { alert(this.self.SPEAKER); }, walk: function() { alert('fiti fiti'); }, fly: function() { alert('pır pır'); } }); var a = new Bird(); a.speak();