Skip to content

Instantly share code, notes, and snippets.

Created January 13, 2016 22:30
Show Gist options
  • Save anonymous/6ac26c859e3f439ba3c2 to your computer and use it in GitHub Desktop.
Save anonymous/6ac26c859e3f439ba3c2 to your computer and use it in GitHub Desktop.
JS Bin // source https://jsbin.com/xetivod
<!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>
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