Created
January 13, 2016 22:30
-
-
Save anonymous/6ac26c859e3f439ba3c2 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/xetivod
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<script id="jsbin-javascript"> | |
function interfaceVerifFunc(toTest, tab){ | |
[].forEach.call(tab, function(elem){ | |
if(typeof toTest[elem] !== 'function'){ | |
throw new Error('bad implement of '+elem); | |
} | |
}); | |
} | |
var action = function(){ | |
this.frapper = function(){ | |
console.log('frappe !'); | |
}; | |
this.test = function(){}; | |
}; | |
var enclencheDecorator = function(actionInstance){ | |
interfaceVerifFunc(actionInstance, ['frapper', 'test']); | |
this.frapper = function(){ | |
console.log('enclencher'); | |
actionInstance.frapper(); | |
}; | |
}; | |
var encaisseDecorator = function(actionInstance){ | |
interfaceVerifFunc(actionInstance, ['frapper', 'test']); | |
this.frapper = function(){ | |
console.log('encaisse'); | |
actionInstance.frapper(); | |
}; | |
this.test = function(){}; | |
}; | |
var creed = new enclencheDecorator( | |
new encaisseDecorator( | |
new action() | |
) | |
); | |
creed.frapper(); | |
</script> | |
<script id="jsbin-source-javascript" type="text/javascript">function interfaceVerifFunc(toTest, tab){ | |
[].forEach.call(tab, function(elem){ | |
if(typeof toTest[elem] !== 'function'){ | |
throw new Error('bad implement of '+elem); | |
} | |
}); | |
} | |
var action = function(){ | |
this.frapper = function(){ | |
console.log('frappe !'); | |
}; | |
this.test = function(){}; | |
}; | |
var enclencheDecorator = function(actionInstance){ | |
interfaceVerifFunc(actionInstance, ['frapper', 'test']); | |
this.frapper = function(){ | |
console.log('enclencher'); | |
actionInstance.frapper(); | |
}; | |
}; | |
var encaisseDecorator = function(actionInstance){ | |
interfaceVerifFunc(actionInstance, ['frapper', 'test']); | |
this.frapper = function(){ | |
console.log('encaisse'); | |
actionInstance.frapper(); | |
}; | |
this.test = function(){}; | |
}; | |
var creed = new enclencheDecorator( | |
new encaisseDecorator( | |
new action() | |
) | |
); | |
creed.frapper(); | |
</script></body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function interfaceVerifFunc(toTest, tab){ | |
[].forEach.call(tab, function(elem){ | |
if(typeof toTest[elem] !== 'function'){ | |
throw new Error('bad implement of '+elem); | |
} | |
}); | |
} | |
var action = function(){ | |
this.frapper = function(){ | |
console.log('frappe !'); | |
}; | |
this.test = function(){}; | |
}; | |
var enclencheDecorator = function(actionInstance){ | |
interfaceVerifFunc(actionInstance, ['frapper', 'test']); | |
this.frapper = function(){ | |
console.log('enclencher'); | |
actionInstance.frapper(); | |
}; | |
}; | |
var encaisseDecorator = function(actionInstance){ | |
interfaceVerifFunc(actionInstance, ['frapper', 'test']); | |
this.frapper = function(){ | |
console.log('encaisse'); | |
actionInstance.frapper(); | |
}; | |
this.test = function(){}; | |
}; | |
var creed = new enclencheDecorator( | |
new encaisseDecorator( | |
new action() | |
) | |
); | |
creed.frapper(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment