Skip to content

Instantly share code, notes, and snippets.

@willmendesneto
Created March 31, 2014 18:02
Show Gist options
  • Save willmendesneto/9898334 to your computer and use it in GitHub Desktop.
Save willmendesneto/9898334 to your computer and use it in GitHub Desktop.
Interface example in Javascript
// 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