JSFiddle - React, Tailwind, and code Playground
by finom
JavaScript
Object.defineProperties( Object.prototype, {
define: {
value: function( key, descriptor ) {
if( descriptor ) {
Object.defineProperty( this, key, descriptor );
} else {
Object.defineProperties( this, key );
}
},
enumerable: false
},
extendNotEnum: {
value: function( key, property ) {
if( property ) {
this.define( key, {
value: property,
enumerable: false,
configurable: true
});
} else {
for( var prop in key ) if( key.hasOwnProperty( prop ) ){
this.extendNotEnum( prop, key[ prop ] );
}
}
},
enumerable: false
}
});
Object.prototype.extendNotEnum({
extend: function( o ) {
for( var i in o ) {
this[ i ] = o[ i ]
}
}
});
Function.prototype.extendNotEnum( 'inherits', function( Parent ) {
var prototype = this.prototype;
this.prototype = Object.create( Parent.prototype );
this.prototype.constructor = this;
this.prototype.extend( prototype );
});
Cat = function() {
this.name = 'Cat';
};
Cat.prototype.miau = function() { alert( 'miau' )}
Dog = function() {
this.name = 'Dog';
};
Cat.prototype.gav = function() { alert( 'gav' )}
CatDog = function() {
var name = '';
Cat.call( this );
name += this.name;
Dog.call( this );
this.name = name + this.name;
}
CatDog.prototype.WTF = function() { alert( 'WTF' ); }
CatDog.inherits( Cat );
CatDog.inherits( Dog );
var catDog = new CatDog();
alert( catDog.name )
catDog.miau()
catDog.gav()