Created
March 31, 2014 18:02
-
-
Save willmendesneto/9898334 to your computer and use it in GitHub Desktop.
Interface example in Javascript
This file contains hidden or 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
// INTERFACE "X" | |
var X = { | |
share: function(clientEmail, email ){} | |
}; | |
// LIB "A" | |
var A = { | |
type: 'facebook' | |
}; | |
// LIB "B" | |
var B = { | |
type: 'twitter' | |
}; | |
// CLASS "XA" | |
var XA = function(A) { | |
this.A = A; | |
}; | |
XA.prototype = Object.create(X); | |
XA.prototype.share = function(clientEmail, email ){ | |
console.log('client: '+clientEmail + ', email: '+email+', type: '+A.type); | |
}; | |
// CLASS "XB" | |
var XB = function() { | |
this.B = B; | |
}; | |
XB.prototype = Object.create(X); | |
XB.prototype.share = function(clientEmail, email ){ | |
console.log('client: '+clientEmail + ', email: '+email+', type: '+B.type); | |
}; | |
var xa = new XA(A); | |
var xb = new XB(B); | |
console.log(xb.share('this is XB content', '[email protected]')); | |
console.log(xa.share('this is XA content', '[email protected]')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment