// Simple compose function (only takes two arguments, most compose functions are variadic)
function compose (a, b) {
return function(){
return a.call(this, b.apply(this, arguments));
};
}
var asElectronic = function (obj) {
obj.voltage = '220v';
return obj;
};
// All sound reproducer are a eletronic
var asSoundReproducer = compose(function (obj) {
obj.watts = 60;
return obj;
},
asElectronic);
var MicroSystem = function(){
this.cd = false;
this.mp3 = true;
};
var TV = function(){
this.pol = 42;
this.hdmi = true
};
// Micro System is a sound reproducer
asSoundReproducer(MicroSystem.prototype);
// TV is a sound reproducer
asSoundReproducer(TV.prototype);
var myTV = new TV();
console.log(myTV);
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.